question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

status: 400, statusText: 'Bad Request'

See original GitHub issue

I keep getting this response when using Axios to get an access token from Instagram.

My Code: `async function mintAuthToken(req: any): Promise<string> { const base = ‘https://api.instagram.com/oauth/access_token’;

const queryParams = { 
  client_id: app_id,
  client_secret: app_secret,
  grant_type: 'authorization_code',
  redirect_uri: redirect_uri,
  code: req.query.code

}

const endpoint = base + qs.stringify( queryParams )

const login = await axios.post(endpoint, {},{headers: {'content-type': 'application/json'}}
);
console.log(login);
const accessToken = login.data.access_token;
const instagramUserID = login.data.user.id;
const profilePic = login.data.user.profile_picture;
const userName = login.data.user.full_name;
console.log(userName);
const firebaseToken = await createFirebaseAccount(instagramUserID, userName, profilePic, accessToken);

return firebaseToken;

};`

The full error: { status: 400, statusText: 'Bad Request', headers: { 'content-type': 'text/html; charset=utf-8', vary: 'Accept-Language', 'content-language': 'en', date: 'Fri, 17 Jan 2020 22:16:38 GMT, Fri, 17 Jan 2020 22:16:38 GMT', 'strict-transport-security': 'max-age=31536000', 'cache-control': 'private, no-cache, no-store, must-revalidate', pragma: 'no-cache', expires: 'Sat, 01 Jan 2000 00:00:00 GMT', 'x-frame-options': 'SAMEORIGIN', 'content-security-policy': 'report-uri https://www.instagram.com/security/csp_report/; default-src \'self\' https://www.instagram.com; img-src https: data: blob:; font-src https: data:; media-src \'self\' blob: https://www.instagram.com https://*.cdninstagram.com https://*.fbcdn.net; manifest-src \'self\' https://www.instagram.com; script-src \'self\' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://*.cdninstagram.com wss://www.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net \'unsafe-inline\' \'unsafe-eval\' blob:; style-src \'self\' https://*.www.instagram.com https://www.instagram.com \'unsafe-inline\'; connect-src \'self\' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://graph.instagram.com https://*.graph.instagram.com https://*.cdninstagram.com https://api.instagram.com wss://www.instagram.com wss://edge-chat.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net chrome-extension://boadgeojelhgndaghljhdicfkmllpafd blob:; worker-src \'self\' blob: https://www.instagram.com; frame-src \'self\' https://instagram.com https://www.instagram.com https://staticxx.facebook.com https://www.facebook.com https://web.facebook.com https://connect.facebook.net https://m.facebook.com; object-src \'none\'; upgrade-insecure-requests', 'x-content-type-options': 'nosniff', 'x-xss-protection': '0', 'x-aed': '15', 'access-control-expose-headers': 'X-IG-Set-WWW-Claim', 'set-cookie': [ 'ig_did=D9E1610B-B50C-4A35-9B7B-6BF0C06AE976; Domain=.instagram.com; expires=Mon, 14-Jan-2030 22:16:38 GMT; HttpOnly; Max-Age=315360000; Path=/; Secure', 'rur=FTW; Domain=.instagram.com; HttpOnly; Path=/; Secure' ], 'x-fb-trip-id': '917726464', connection: 'close', 'content-length': '11' }, config: { url: 'https://api.instagram.com/oauth/access_tokenclient_id=client id&client_secret=secret&grant_type=authorization_code&redirect_uri=redirect&code=somecode', method: 'post', data: '{}', headers: { Accept: 'application/json, text/plain, */*', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'axios/0.19.0', 'Content-Length': 2 }, transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 0, adapter: [Function: httpAdapter], xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, validateStatus: [Function: validateStatus] }, request: ClientRequest { domain: Domain { domain: null, _events: [Object], _eventsCount: 1, _maxListeners: undefined, members: [Array] }, _events: { socket: [Function], abort: [Function], aborted: [Function], error: [Function], timeout: [Function], prefinish: [Function: requestOnPrefinish] }, _eventsCount: 6, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 0, writable: true, _last: true, upgrading: false, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedConnection: false, _removedContLen: false, _removedTE: false, _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: TLSSocket { _tlsOptions: [Object], _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: 'api.instagram.com', npnProtocol: undefined, alpnProtocol: false, authorized: true, authorizationError: null, encrypted: true, _events: [Object], _eventsCount: 9, connecting: false, _hadError: false, _handle: [Object], _parent: null, _host: 'api.instagram.com', _readableState: [Object], readable: true, domain: [Object],}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15

github_iconTop GitHub Comments

1reaction
b02505048commented, Feb 28, 2020

I also have the same problem with Axios and solved by using curl-request.

There’re a ton of problems with calling Instagram API using Axios on StackOverflow.

However, I still believe that Axios should be able to behave like cURL. Let’s see who could provide an equivalent solution in the short future…

1reaction
rlee1990commented, Jan 20, 2020

I have checked with Instagram it works when I send a curl request it works but when I send it using axios in firebase cloud functions I am using stringify to string it all in the url

Read more comments on GitHub >

github_iconTop Results From Across the Web

400 BAD request HTTP error code meaning? - Stack Overflow
A 400 means that the request was malformed. In other words, the data stream sent by the client to the server didn't follow...
Read more >
400 Bad Request Error: What It Is and How to Fix It
The 400 Bad Request Error is an HTTP response status code indicating that the server was unable to process the request sent by...
Read more >
How to Fix the 400 Bad Request Error - Lifewire
The 400 Bad Request error means that the request you sent to the website server to view the page was somehow incorrect.
Read more >
How to Fix a 400 Bad Request Error: 8 Easy Methods
The 400 bad request error is an HTTP status code that describes an error caused by an invalid request. Thus, the server can't...
Read more >
How to Fix a 400 Bad Request Error (Causes and Fixes) - Kinsta
The 400 (Bad Request) status code indicates that the server cannot or will not process the request due to something that is perceived...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found