question

Upvotes
Accepted
1 0 0 1

'401', 'message': 'token expired', 'status': 'Unauthorized'

I am using QPS via RDP and get this error:

Processing 104 Trade Id: 623723993 Trade Date: 2024-04-29 Expiry Date 2024-05-20 Ccy Pair: USD.JPY
{'error': {'id': '9e917473-7aee-419c-ab9b-66eff931f720', 'code': '401', 'message': 'token expired', 'status': 'Unauthorized'}}

How do I resolve this?

#technologyrdp-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
26.3k 61 17 14

Hello @navtej.riyait

The error 'code': '401', 'message': 'token expired', 'status': 'Unauthorized' means the RDP access token that included in the API request header has been expired.

Basically, when you request the access token from the RDP Authentication service (/auth/oauth2/v1/token), you get the following "mandatory" information from the API:

  • access_token: The token used to invoke REST data API calls
  • refresh_token: Refresh token to use used for getting next access token
  • expires_in: Access token validity time in seconds

The access token validity time is available on the expires_in variable.

The best practice is you need to refresh the token to get the new access token before the expires_in time in seconds:

The HTTP request for the RDP APIs Authentication service refresh token is as follows:

POST /auth/oauth2/v1/token HTTP/1.1
Accept: */*
Content-Type: application/x-www-form-urlencoded
Host: api.refinitiv.com:443
Content-Length: XXX

refresh_token={current_refresh_token}
&grant_type=refresh_token
&client_id=RDP_APP_KEY

Once the authentication success, the function gets access_token, refresh_token, and expires_in from the RDP Auth service response message the same as the previous RDP Authentication call. An application must keep those value for the next Refresh Token call.

You can find more detail about the token information from this RDP tutorials: Authorization - All about tokens page.

Caution: API Limit

The RDP Authentication service has the API limit described on the RDP APIs: Limitations and Guidelines for the RDP Authentication Service article. If the application flushes the authentication request messages (both password and refresh_token grant_type) beyond the limit, the account will be blocked by the API Gateway.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
10.6k 20 6 9

@navtej.riyait Thanks for your question and sorry to hear about your issue - so we have an article about Tokens and the token workflow - I take it you are not using the Refinitiv Data Libraries as these do session/token management for you. If you are accessing the platform directly you will need to manage initial access and refresh tokens:

1715167794869.png


We have an article that explains this in detail with code samples. I hope this can help.


1715167794869.png (270.9 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Are there python code examples for checking expires_in and refresh token ?

Upvotes
1 0 0 1

Are there python code examples for checking expires_in and refresh token ?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Yes, there are quickstart and tutorials with downloadable python samples.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.