OAuth Step 4 issue

I’ve been trying to figure out this series of errors for awhile now and the errors in the docs are just incredibly unhelpful with how vague they are.

Here’s my code (I’m using NodeJS):
function handleOAuthRedirectRequest (req, res) {
let {code} = req.query
axios.post(https://www.patreon.com/api/oauth2/token?code=${code}&grant_type=authorization_code&client_id=${patreonId}&client_secret=${patreonSecret}&redirect_uri=${redirect}, {}, {headers: {‘Content-Type’: ‘application/x-www-form-urlencoded’}})
.then(result => console.log(result))

And I’m getting a 401 { error: ‘invalid_grant’ }.

When I change it to …&grant_type=_code&client_id…
I get 400 { error: ‘unsupported_grant_type’ }

I’ve also tried pushing everything through in the body and that didn’t work either.

What do these errors mean? What am I doing wrong?

Peculiar! I don’t see any issue on first glance.

In the 401 response, there should a request id. Can you send that our way, so we can look into the request to see more details around what’s going on?

It is.

So, the error isn’t a 401 - it’s 400, so there’s something about the request that’s bad but I’m not sure what it is and both errors I’m getting aren’t helpful

So you’re saying this one is actually a 400? Is there a request id in the response body?

Yeah, that’s correct - I mistyped and it should be 400.

Are you talking about what’s underlined in red here:

Because the body of the response object I’m getting back only has data: {error: ‘unsopported_grant_type’}

Nothing yet, huh? Must be quite an issue to take more than 2 weeks to fix