Using Oauth2 with Glide

Hello all

I am trying to write a simple app to integrate with my online financial software - FreeAgent - mainly to test out my skills / learn.

FreeAgent uses OAuth 2.0

I realise it is best practice to do the handling of tokens outside of Glide - but as it is just me using it - and I am just playing - I thought I would give it a go within Glide (and I have no idea how to handle the tokens outside anyway!)

I’ve created an app in my financial software - and am able to Grant access to my Glide app - and have got an authorisation code back from FreeAgent.

As I understand it from the docs, I now need to exchange that code for Access and Refresh Tokens.

I’ve been able to get both tokens using Curl - but can not get the CallAPI action to succeed in Glide. I get a 400 error usually. I realise the Authorisation token expires and is one use (took me a while to find that out!)

This is my Curl statement that works (with the codes removed)

curl -X POST “https://api.freeagent.com/v2/token_endpoint” \

-H “Authorization: Basic XXX” \

-H “Content-Type: application/x-www-form-urlencoded” \

-d “grant_type=authorization_code&code=XXX&redirect_uri=https%3A%2F%2Ffreeagent.glide.page%2Fdl%2F17171d”

Any ideas why the CallAPI action wouldn’t work? I am passing the code in as a variable into the Body and have the Authorisation and Content Types correctly set in the headers.

Thanks in advance
Andrew

Have you Base64-encoded the “XXX” part in your Authorization: Basic header?

Is the code=XXX part different from the header code? I assume it is?

Hi
Thanks for this.

Yes I have encoded the client id and secret in base64

I’ve actually copied and pasted each value exactly as per my curl statement and get the same 400 error

Do the exact same values in the Glide API column, pasted into curl works in curl but not Glide.

I’ve also tried using dynamic values for each field.

Am slightly stumped!

Now looking to use Google Apps script to manage token refresh inbetween FreeAgent and glide but would love to get this working if I can.

Hi all

Hope you’re having good weekends.

I’ve made some great progress with my FreeAgent / Glide app. I now have the OAuth 2.0 process working really well - by using a Google Apps Script between Glide and FreeAgent to handle the token exchange. Means that Glide only needs to store Client ID and retrieve a token every hour (or when needed) from GAS. Rather pleased with myself! Happy to share more info if it helps anyone else.

But now I am stumped on another part. I send an API call to FreeAgent to add an attachment (a receipt) to a transaction. I have worked out how to do it, and can successfully add receipts using postman to test. Works every time.

But when I do the same using a call API action in Glide - I get a 400 error.

I have checked over and over all the values - and they are identical.

Any reason why the call API would fail? Are there any restrictions / limits? I have made the attachment very small (100kb) - which is encoded in base64.

Is there a way of getting more debugging info back from Glide? I just get a 400 error and the following in the logs (which is what I am sending only). I have a column to write the response to - but that does not get completed. It is left blank.

It’s the exact same issue I raised in my first post in this thread, so am concerned it’s something to do with the way Glides call API handles these requests. Though other calls (mainly get) have worked nicely.

Any help much appreciated!

Andrew

Data sent by Glide to the API (with encoded attachment and Bearer truncated)

{

“body”:"{ “bank_transaction_explanation”: { “attachment”: { “file_name”: “test.png”, “data”: “iVBORwkQrEEYj+IfXJzZ…”

“method”:“PUT”

“headers”:{

“Authorization”:{

“value”:“Bearer 1ABzcAlXHFtnmI1ZSwDZxQ3-XFH”

“isSecret”:false

}

}

“endpoint”:“https://api.freeagent.com/v2/bank_transaction_explanations/536662117

“queryString”:{

“Content-Type”:{

“value”:“253b57e7-1733-4f55-9b0d-f2c83b9e7907”

“isSecret”:true

}

}

Shouldn’t the Content-Type part be in the header, and the value being “application/json”? Or does it work differently for FreeAgent?

Also, have you truncated your body? Is it a JSON you constructed in Glide?

Thanks so much - can’t believe I missed that! That was exactly it - I had my Content Type in the Query String section… :man_facepalming:

Putting it into the Header section (and undoing all the other changes I’d made to try and trouble shoot!) and it worked.

Very quick question - Glide sends the values as a secret - so my content Type value - application/json - shows as “6c78bb96-3c76-4993-92f1-d3cb82988985”. Is that something that is done in the backend to keep it secret? Assume so

Thanks again for taking the time to read through my JSON and spotting the error. Much appreciated!

Andrew

Yeah that must be it. Glad you got it sorted!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.