API call - Failed to load resource: net::ERR_NAME_NOT_RESOLVED
-
I've been trying to use the API to make a post.
For testing purposes I put a function in the custom JS area to try this.The docs didn't give a full payload example, so I made my best guess at the headers and where API key goes. This is what I tried
const bodyData={ "cid": 1, "title": "Test topic", "content": "This is the test topic's content", "timestamp": 556084800000, "tags": [ "test", "topic" ] } const key='c562 ... ' // redacted const option = { method: 'POST', headers: { 'content-type': 'application/json', authorization: `Bearer `+key }, body: JSON.stringify(bodyData) }; alert('Fetching API') fetch( 'https://aignite.nodebb.org/api/v3/topics/', option ) .then(response => response.json()) .then( data=> {alert("Api")} ) .catch(error => alert('err='+error) )
The alert fired, but no post was created and console error -
Failed to load resource: net::ERR_NAME_NOT_RESOLVED aignite.nodebb.org/api/v3/topics/:1Can anyone advise, have I structured the API call incorrectly?
-
@julian said in API call - Failed to load resource: net::ERR_NAME_NOT_RESOLVED:
'x-csrf-token': config.csrf_token,
It worked!Just so I can understand, it seems the custom JS area has access to the value of config.csrf_token,
If it was external code, how could I get that config.csrf_token value? -
I think I might know why though. Can you do me a favour and update the code to add
credentials: 'omit'
tooptions
, and then comment out the line adding the csrf token?I think what is happening is that when
fetch()
sends the request, it also sends the session cookie. NodeBB checks the session cookie, finds an active session, and uses that user, and ignores the bearer token.