Unable to obtain token for API

I am trying to test out the Torizon Cloud API and following the documentation as shown at the two links here:

The second link shows that I need to go to https://kc.torizon.io/auth/realms/ota-users/protocol/openid-connect/token to obtain a token to authorize the API, however I get this error.

image

Am I missing a step or is something wrong on the Torizon side of things?

Hi, I’m the Toradex AI Assistant. I’m in early beta, and I would appreciate your feedback.
The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello,

To troubleshoot the issue with obtaining a token for the Torizon Cloud API, please ensure the following steps have been correctly followed:

  1. Registration and Login: Verify that you have a registered account on the Torizon Cloud and that you are able to log in successfully. The token acquisition process requires valid user credentials.

  2. Client Credentials: Ensure that you have created a client in the Torizon Cloud with the appropriate permissions and that you are using the correct client ID and secret when requesting a token. This information is critical for the authentication process.

  3. Correct URL and Parameters: Double-check the URL you are using to request the token. It should match exactly with the one provided in the documentation. Additionally, ensure that the request parameters (such as grant_type, client_id, client_secret, and possibly scope) are correctly formatted and included in your request.

  4. HTTP Method and Headers: The token request typically needs to be made using the POST method, and it may require specific headers, such as Content-Type: application/x-www-form-urlencoded. Verify that your request conforms to these requirements.

  5. Error Messages: Pay close attention to any error messages returned by the server. They can provide valuable clues about what might be going wrong. Common issues include invalid credentials, incorrect or missing request parameters, or problems with the client configuration on the server.

If after checking these steps you still encounter issues, it might be helpful to use a REST client tool or command-line utility like curl to manually craft and send the token request. This can offer more control over the request parameters and headers, and may help isolate the issue.

Example curl command to request a token (replace placeholders with your actual client ID and secret):

curl -X POST https://kc.torizon.io/auth/realms/ota-users/protocol/openid-connect/token \
-d 'grant_type=client_credentials' \
-d 'client_id=YOUR_CLIENT_ID' \
-d 'client_secret=YOUR_CLIENT_SECRET'

Ensure that your network configuration allows access to the token URL and that no firewall or proxy settings are interfering with the request.

Best regards,
Toradex AI Assistant

Please, also check if these links can help you solve your problem:

Build and Run the Amazon SageMaker Edge Manager Demo on Torizon | Toradex Developer Center.

Using the curl POST suggested by the AI provided me with an access token, but when I try to put this information to the authorize on the API docs, I am still getting an error.

image

It looks like maybe I am authorized now, but I’m not sure what the above error is from. When I try to run the get metrics I get a 200 response, but not data.

image

Is my timestamp not correct?

Hi @dleberfinger

The way I usually do these is to generate the token at the command-line. Something like the following should work:

TDX_TOKEN=$(curl -s https://kc.torizon.io/auth/realms/ota-users/protocol/openid-connect/token \
                 -d client_id=$client_id \
                 -d client_secret=$client_secret \
                 -d grant_type=client_credentials | jq -r .access_token)
echo $TDX_TOKEN

where you have previously set the client_id and client_secret environment variables.

Then copy/paste the token that is printed into the BearerAuth field of the Swagger “Authorize” dialog box.

Hope that helps.
Drew

Drew,

This is what I did after I saw the AI suggestion. Do you have any information about the failed to fetch error when I tried to authorize or the reason why I can’t seem to pull the temp data with the API?

Hmm. At the risk of being unhelpful, it “works for me”. :wink:

To clarify are you using a client type of API V2(Beta)?

Drew

@dleberfinger,

Do you have any information about the failed to fetch error when I tried to authorize

I’m not quite sure how you get this fetch error, I’m unable to get this error myself. This is assuming you’re using the proper api v2 token as Drew has said.

the reason why I can’t seem to pull the temp data with the API?

As for the lack of data in the API response. The API here requires Unix epoch time in milliseconds. Your timestamp values look like they’re in seconds, basically you want to add 3 0’s to your time values to get Unix epoch milliseconds.

If I do a similar request with my values in seconds I get no data points like you did, once I convert to milliseconds I get appropriate values as expected. So I’m pretty sure that is the issue you’re having on this point.

Best Regards,
Jeremias

2 Likes

@jeremias.tx

Thank you! The seconds to milliseconds solved the issue. I am able to pull data now.

1 Like

Glad I was able to clarify.