#api/import

17 messages · Page 1 of 1 (latest)

torn kayak
#

when I make this request the server sends me forbidden while the request is good?

            axios({
                method: 'post',
                url: 'https://lichess.org/api/import',
                data: {
                    'pgn': match_pgn
                },
                Headers: {
                    'authorization': '...',
                }
            }).then((res) => {
                let result = res.data
            
                console.log(res)
            }).catch((err) => {
                console.log(err)
            })```

```js
 AxiosError: Request failed with status code 403

method: 'post',
url: 'https://lichess.org/api/import',
data: '{"pgn":"[Event \\"Live Chess\\"]\\n[Site \\"Chess\\"]\\n[Date \\"2023.06.10\\"]\\n[White \\"Denizio151\\"]\\n[Black \\"tonykun7\\"]\\n[Result \\"0-1\\"]\\n[ECO \\"C42\\"]\\n[TimeControl \\"180\\"]\\n[EndTime \\"12:08:28 PDT\\"]\\n[Termination \\"tonykun7 won by checkmate\\"]\\n[SetUp \\"1\\"]\\n[FEN \\"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1\\"]\\n\\n1. e4 e5 2. Nf3 Nc6 3. d3 Nf6 4. Nc3 d5 5. exd5 Nxd5 6. d4 e4 7. Ne5 Nxd4 8. Bb5+ c6 9. Nxc6 bxc6 10. Bxc6+ Bd7 11. Bxd5 Bb4 12. a3 Bxc3+ 13. bxc3 O-O 14. cxd4 g6 15. Bxe4 h5 16. Bh6 Re8 17. O-O Bg4 18. f3 Bf5 19. Bd3 Bxd3 20. cxd3 Rb8 21. Rc1 Qxd4+ 22. Kh1 Rb2 23. g4 hxg4 24. fxg4 Rf2 25. Rxf2 Qxf2 26. d4 Re2 27. d5 Qxh2# 0-1"}',
Headers: { authorization: '...' }```
neat robin
#

Hmm... Your '...'...
Do you have Bearer ...?
Like authorization: Bearer lip_...

And is there any text in the response body?

#

And the documentation, https://lichess.org/api#tag/Games/operation/gameImport, seems to indicate that the request body schema should be application/x-www-form-urlencoded

In your text below the AxiosError, it looks like the data is json-formatted?
I don't know if that's what's being sent or if that's how your logger logs things..

lofty ridge
#

You need that

torn kayak
#

same error with Bearer

#
            axios({
                method: 'post',
                url: 'https://lichess.org/api/import',
                data: {
                    'pgn': match_pgn
                },
                Headers: {
                    'authorization': 'Bearer lip_....',
                    'content-type': 'application/x-www-form-urlencoded'
                }
            }).then((res) => {
                let result = res.data
            
                console.log(result)
            }).catch((err) => {
                console.log(err)
            })```


```js
Cross origin request forbidden```
torn kayak
lofty ridge
#

are you sure "Headers" is supposed to be uppercased?

#

also, you probably want to send a accept: application/json header now. but that won't change whether it succeeds or not.

torn kayak
lofty ridge
#

And please don't ping me on responses

torn kayak
torn kayak
#
                headers: {
                    'authorization': 'Bearer lip_....',
                    'content-type': 'application/x-www-form-urlencoded',
                    'content-type': 'application/json'
                }```

return html page
lofty ridge
#

The header is "accept" as written in my message ..