I'm trying to call an Instagram API call from my server (nodeJS) and I am not sure how to do so.
curl -X POST https://api.instagram.com/oauth/access_token \
-F client_id=123456... \
-F client_secret=123abc... \
-F grant_type=authorization_code \
-F redirect_uri=https://google.sg/ \
-F code=123abc
This command returns the desired output when I run it on the command line, but I can't seem to find a way to do the same in JavaScript. Here is what I've tried:
axios
.post("https://api.instagram.com/oauth/access_token", {
client_id: 123456...,
client_secret: "123abc...",
grant_type: "authorization_code",
redirect_uri: "https://google.sg",
code:
"123abc...",
})
This is what is logged in by the catch block:
data: {
error_type: 'OAuthException',
code: 400,
error_message: 'Missing required field client_id'
}
I think -F
refers to form data, but I can't seem to find a way to do that in axios.
edit: I've tried it with just client_id
, and it returns the same error.
edit 2: I don't think this is a fix but Postman Agent has a nifty function to translate the HTTP request into code:
It can be accessed via Code
on the right.