Invalid_grant error in Bubble.io (Exchange code for token - Discord oAuth)

I am completely stuck here… the authorization works fine, but keep getting the following error when i initialize my POST request to exchange an oAuth code for a token. This is using Bubble.io and Discord’s API.



image

You’ve formatted the body of your api call incorrectly. It must be Json formatted which will look something like the following

{
“client_id” : “your client ID here”,
“client_secret” : “your secret here”
}

But it says to format it as www-form-urlencoded

Then use the option to add a parameter. You can’t use the body section the way you are in my experience

It wants a Json object

Ok, thanks. I’ll try it out. I had watched a video because I am not too experienced with APIs and it said to do that. Looking back, I think I did do that at one point but got an invalid_client errror. Do you know how I might fix that?

Ok, sorry, it’s a different error now.
image

Share a screenshot of the api docs if you can

Here’s the specific part that covers exchanging codes for tokens. If you need a screenshot of it let me know but it might be easier to just check out the docs itself. I appreciate the help. Discord Developer Portal

Change your body type to form so the body isn’t showing anymore

Thanks, that yields the same error but a different description.

So this is the entire API itself (not a call), should I try this. I changed the authentication drop-down from OAuth2 User-Agent Flow to OAuth2 Custom Token

different error. it’s saying the code you sent is invalid.

So I would have to re-authorize in run-mode and get the new code?

every time

What do you mean?

every time you send a code, you need to reauthorize and grab a new code (most likely, unless that code hasn’t been exchanged and is still valid. codes are short-lived)

Yea, so basically you’re saying each time someone authorized I have to exchange that code for both a refresh and an access token and then regenerate the access token using the refresh token each time the access token expires (1hr)?

exactly! that’s the oAuth dance!

Yea but doesn’t bubble do that automatically when using the User-Agent Flow? Or how do I set it up so that each API call I make under an API uses the token generated from the User-Agent Flow oAuth authorization?

Because whenever I create API calls, it returns a not authorized error