Best answer

Sending my access token from OAuth 2 authentication to api call in subsequent zap step

  • 9 March 2022
  • 6 replies
  • 897 views

Userlevel 1

Hi,

 

I am building a zap to get data from my Quickbooks Online account when an estimate is updated, and since it uses oauth 2 authentication, I created an integration, now I do not have any issue with getting the authentication to work and the test api at the end of authentication also returns a response successfully. My issue is with making subsequent api calls after I add the integration as a trigger to my zap, I am trying to make an api call to quickbooks but require the access_token to be sent in the header. I do not know how to access the value of access_token.

I have tried using {{bundle.authData.access_token}} but it shows “no data”, also tried {{bundle}}, the bundle object itself is shown as “no data”. Requesting some help with this.

Thank you for your time!

icon

Best answer by Ashwinnn 11 March 2022, 07:59

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

6 replies

Userlevel 7
Badge +9

You mention that the auth config test API request succeeds. If that test request is configured properly it should be exercising the usage of the auth variables and confirming they are populated correctly. I’d start by looking at what’s different in the request configuration in the auth test request vs. your trigger implementation.

If you post both configurations here perhaps someone can help spot the issue.  

Userlevel 1

You mention that the auth config test API request succeeds. If that test request is configured properly it should be exercising the usage of the auth variables and confirming they are populated correctly. I’d start by looking at what’s different in the request configuration in the auth test request vs. your trigger implementation.

If you post both configurations here perhaps someone can help spot the issue.  

Hi @Zane thank you for responding. I was able to come up with a workaround for this. I created an action to call an api from quickbooks and returned bundle.authData instead of the api response and was then able to use the access_token from there in my zap.

However, I now face a different issue. The access_token is valid for 1 hour and after the 1 hour is up, all api requests to Quickbooks return “invalid_client” with 401 status, my assumption was that Zapier would automatically run the authentication flow again to get a new access_token but unfortunately nothing of that sort happens and I have to reconnect the account to proceed with running my Zap. Any idea why Zapier does not automatically call for access_token after getting a 401 on an api.response ?

Appreciate you taking your time to read through this!

Userlevel 7
Badge +9

This sounds like the OAuth config is misconfigured. You shouldn’t be having to get a token from an action. 

Good news is when we get you properly set up, the OAuth config will address the refresh issue automatically. So I’d focus on getting your Auth config working correctly and abandon your workaround. You might take another run through of https://platform.zapier.com/docs/oauth and see if that helps you spot the problem. Again, if you post more details of your configuration the community might be able to provide more specific guidance. 

Userlevel 1

Hi @Zane, appreciate you getting back to me on this. Attaching a screenshot of my auth config for your reference, also adding a screenshot of how I send back {{bundle.authData.access_token}} to my Zap.

Thank you for your time!

Userlevel 1

A quick update regarding this issue,

I dug more into QBO documentation for oauth2 and found that there was a mismatch in the docs, they mention the Authorization header should contain the access_token when requesting for a new refresh token but it should contain the base64 encoded string of client_id:client_secret, so got the refresh_token refresh call to work by changing the value of authorization header.

Also, removed the Get access_token action block and was able to send the bundle.authData in the Perform block of the trigger, so I am now sending an array of objects containing bundle.cleanedRequest and bundle.authData from the trigger perform block.

 

Thank you very much @Zane for pointing me in the right direction. 

Added solution incase anyone faces the same question in the future!

Userlevel 7
Badge +11

That’s fantastic, great work here @Ashwinnn:tada:

And thanks so much for sharing your solution here with the Community. I’m sure others will find it super helpful! :relaxed: