cancel
Showing results for 
Search instead for 
Did you mean: 

API call when using HTTP-connector fails because invalid_token was used in oauth2

vbosma
Deputy Chef II
Deputy Chef II

Hi, when reaching out to an application with the HTTP connector I often get an error for "invalid_token, the access token provided has expired". This seems to happen every time a new token is needed for a call. When repeating the job, the call goes just fine. 

First call result:

Schermafbeelding 2026-02-05 124927.pngSchermafbeelding 2026-02-05 131738.png

 

 

 

 

 

Second call result:

Schermafbeelding 2026-02-05 1322372.png

Schermafbeelding 2026-02-05 131836.png

Schermafbeelding 2026-02-05 1318521.png

 

Does anyone have an idea what the cause could be? Also I never encounter this problem using Postman.

To mee it seems like the token was used too quickly for the target application to be able to validate the token. 
In the debug of the HTTP request I see no details of the actual headers/payload/response
What is the best-practice solution I could try?

I have not seen anything like a delay in the HTTP connector settings and it seems to extreme to make a custom connector.

The target application accepts the usual Oauth2 flow, with grant_type: client_credentials.
This results in a bearer token for all following calls.

I look forward to your inspiration, also: please let me know if this is not the right place for this question.

Kind regards,

Vincent

 

1 ACCEPTED SOLUTION

Hi @vbosma, for the First workaround can you send the response/error of the http action?

How the second workaround, you can create two http invocation if possibile: 

  • First invocation: you send http request at url to receive in the response the access token;
  • Second invocation: you send http request with authentication token.

View solution in original post

11 REPLIES 11

francbaviello
Deputy Chef III
Deputy Chef III

Hi @vbosma, the behavior appears to be due to an internal Workato race condition during automatic OAuth token refresh:

  • When Workato detects an expired token, it initiates the token renewal request;
  • However, the call to the protected endpoint is initiated before the new token is actually saved and applied to the Authorization header;
  • As a result, the first request is sent with an invalid (or absent) token and is rejected by the API;
  • The subsequent call works correctly because the token has been refreshed in the meantime.

This explains:

  • the error only on the first call,
  • the fact that the immediate retry succeeds,
  • the absence of the problem in Postman (which executes the OAuth flow strictly sequentially).

 

As a workaround, you can evaluat:

  • manual OAuth token management (explicitly separating the token request and API call);
  • or implementing an automatic retry in the event of a 401 / invalid_token error.

Hi  francbaviello,

Thank you for your quick reply and detailed explanation. The first automatic retry was my first idea too, but then I noticed that the invalid_token response still has a 200 OK status.

So now I put in an IF statement, and then put a WAIT block for 5 seconds, to retry again.. which also has an IF statement to alert if the response is the same. 

Do you consider this a proper work-around? The recipe looks like this:

Schermafbeelding 2026-02-05 160325.png

Hi @francbaviello , I just retried and noticed even this workaround is not proof.. there was still an invalid_token error:
The wait specified length of time is set to 5 seconds, but this does not seem to be enough either.
I might have to check your manual Oauth token management or  hope you guys have another way.

Schermafbeelding 2026-02-05 162145.png

Token expiration is silly, so I choose not to deal with it.

The 🚨 API Police 🚨 probably don't like this, but I always request a new token for every API call.

I split the process into two HTTP actions: one to get the token, then another to make the call with the token.