Problems with the JWT token testing the API

Hello, I’m trying to test the API to create a simple workflow.

The process I do is:

  1. I sign up at Edge Impulse and get the API Key of my user.
  2. I go to the Edge Impulse Docs and i create a JWT Token successfully with my API Key.
  3. To test that the JWT token works good I go to Get current user API call here and I introduce my JWT token as cookie and when i run it I go an infinite loop into the docs.

Opening the Browser console I can see the error:


Access to fetch at 'https://try.readme.io/https://studio.edgeimpulse.com/v1/api/user' from origin 'https://docs.edgeimpulse.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.

I tried to use Postman to see if I could made it run. I got the JWT token successfully. Then to test the GET Current user i’m unable to introduce the JWT token as a Cookie on the Postman interface.

An error I’m getting is:

{
    "success": false,
    "error": "Missing x-api-key header"
}

Finally, if i copy the curl instructions from the website and I go to my terminal everything works great.

Any idea why this is not working on my side on the docs or on Postman? Thanks :slight_smile:

Hola Marc,

On Edge Impulse documentation website, can you try changing from cookie to --header 'x-jwt-token

curl --request GET \
     --url https://studio.edgeimpulse.com/v1/api/user \
     --header 'Accept: application/json' \
     --header 'x-jwt-token: <JWT_TOKEN>'

I tried on both my terminal with cURL and on the documentation website and it seems to work fine.
Let me know if that works on Postman too with this header.

Regards,

Louis

1 Like

Thank for pointing to the solution about using the header x-jwt-token. If you can clarify on the docs, that would be awesome :slight_smile:

What I see is in Postman, is that if i’m using Auth inheriting auth parameters with x-api-token the error always is:

{
    "success": false,
    "error": "This API is only available through JWT token authentication"
}

even if the x-jwt-token is part of the headers. Is that correct?

The Edge Impulse docs page here still show me infinite loops instead of errors.

Hi @mpous,

The docs for all of the User API calls say that “This function is only available through a JWT token.” Was there another place you recommend it being listed?

From what I understand, the API keys are project-specific, so creating a request to, say, get user, with that key likely won’t work. Can you provide a screenshot of the infinite loop? I just tried that page, and I get a a regular error.

Best,

Shawn