Need Help with NodeJS Integration

Solved!
Posted in General by Ritej Bisaria Sun Jan 22 2017 15:57:23 GMT+0000 (UTC)·2·Viewed 585 times

My code is in NodeJS : request({ url: 'https://test.instamojo.com/oauth2/token/', //URL to hit method: 'POST', //Lets post the following key/values as form form: { client_id: 'MJ6HmHbJ5Sp6s5jVPTLH3j86AGDeGu3RmQp4tmKR', client_secret: 'kQT5nMz4cN8AFfvyhEv38594nXfRKF4ds0IpiVU101gEWN8XmI5pMoSl7rAeSC1VVTRejUK3KNeytAMeJIs6CoweufkCMNZD9KjrtzM4LqmmE5k9v6NtKo0VzYken7hB', grant_type: 'client_credentials' } }, function(error, response, body){ if(error) { console.log(error); } else { console.log(response); res.json({ success:true, data:body, error:null }) } }); The response this is giving is: req: ClientRequest { domain: null, _events: { drain: [Function], error: [Function], response: [Function] }, _eventsCount: 3, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 437, writable: true, _last: true, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedHeader: { 'content-length': false }, _contentLength: 223, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: TLSSocket { _tlsOptions: [Object], _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: null, npnProtocol: false, authorized: true, authorizationError: null, encrypted: true, _events: [Object], _eventsCount: 9, _connecting: false, _hadError: false, _handle: null, _parent: null, _host: 'test.instamojo.com', _readableState: [Object], readable: false, domain: null, _maxListeners: undefined, _writableState: [Object], writable: false, allowHalfOpen: false, destroyed: true, bytesRead: 604, _bytesDispatched: 437, _sockname: null, _pendingData: null, _pendingEncoding: '', ssl: [Object], server: undefined, _requestCert: true, _rejectUnauthorized: true, parser: null, _httpMessage: [Circular], read: [Function], _consuming: true, _idleNext: null, _idlePrev: null, _idleTimeout: -1 }, connection: TLSSocket { _tlsOptions: [Object], _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: null, npnProtocol: false, authorized: true, authorizationError: null, encrypted: true, _events: [Object], _eventsCount: 9, _connecting: false, _hadError: false, _handle: null, _parent: null, _host: 'test.instamojo.com', _readableState: [Object], readable: false, domain: null, _maxListeners: undefined, _writableState: [Object], writable: false, allowHalfOpen: false, destroyed: true, bytesRead: 604, _bytesDispatched: 437, _sockname: null, _pendingData: null, _pendingEncoding: '', ssl: [Object], server: undefined, _requestCert: true, _rejectUnauthorized: true, parser: null, _httpMessage: [Circular], read: [Function], _consuming: true, _idleNext: null, _idlePrev: null, _idleTimeout: -1 }, _header: 'POST /oauth2/token/ HTTP/1.1\r\nHost: test.instamojo.com\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: node-superagent/2.3.0\r\nContent-Type: application/x-www-form-ur lencoded\r\nContent-Length: 223\r\nConnection: close\r\n\r\n', _headers: { host: 'test.instamojo.com', 'accept-encoding': 'gzip, deflate', 'user-agent': 'node-superagent/2.3.0', 'content-type': 'application/x-www-form-urlencoded', 'content-length': 223 }, _headerNames: { host: 'Host', 'accept-encoding': 'Accept-Encoding', 'user-agent': 'User-Agent', 'content-type': 'Content-Type', 'content-length': 'Content-Length' }, _onPendingData: null, agent: Agent { domain: null, _events: [Object], _eventsCount: 1, _maxListeners: undefined, defaultPort: 443, protocol: 'https:', options: [Object], requests: {}, sockets: [Object], freeSockets: {}, keepAliveMsecs: 1000, keepAlive: false, maxSockets: Infinity, maxFreeSockets: 256, maxCachedSessions: 100, _sessionCache: [Object] }, socketPath: undefined, method: 'POST', path: '/oauth2/token/', parser: null, res: IncomingMessage { _readableState: [Object], readable: false, domain: null, _events: [Object], _eventsCount: 4, _maxListeners: undefined, socket: [Object], connection: [Object], httpVersionMajor: 1, httpVersionMinor: 1, httpVersion: '1.1', complete: true, headers: [Object], rawHeaders: [Object], trailers: {}, rawTrailers: [], upgrade: false, url: '', method: null, statusCode: 401, statusMessage: 'Unauthorized', client: [Object], _consuming: true, _dumped: false, req: [Circular], text: '{"error": "invalid_client"}', read: [Function], body: [Object] } }, links: {}, text: '{"error": "invalid_client"}', body: { error: 'invalid_client' }, files: undefined, buffered: true, headers: { date: 'Sun, 22 Jan 2017 10:45:42 GMT', 'content-type': 'application/json', 'transfer-encoding': 'chunked', connection: 'close', server: 'nginx', 'x-frame-options': 'SAMEORIGIN', vary: 'Cookie', 'cache-control': 'no-store', pragma: 'no-cache', 'set-cookie': [ 'csrftoken=WYIpctfKYGTGCyRMF3lyLDnyV0GTcTarJ9qmFLJ4vxI1B5SjyJPUzpeCB4MYGNfT; expires=Sun, 21-Jan-2018 10:45:42 GMT; Max-Age=31449600; Path=/; secure' ], 'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff', 'strict-transport-security': 'max-age=31536000', p3p: 'CP="Instamojo does not have a P3P policy"' }, header: { date: 'Sun, 22 Jan 2017 10:45:42 GMT', 'content-type': 'application/json', 'transfer-encoding': 'chunked', connection: 'close', server: 'nginx', 'x-frame-options': 'SAMEORIGIN', vary: 'Cookie', 'cache-control': 'no-store', pragma: 'no-cache', header: { 'content-type': 'text/html', 'last-modified': 'Wed, 09 Sep 2015 10:51:38 GMT', 'accept-ranges': 'bytes', etag: '"fa62cb80edead01:0"', server: 'Microsoft-IIS/7.5', 'x-powered-by': 'ASP.NET', date: 'Sun, 22 Jan 2017 15:34:49 GMT', connection: 'close', 'content-length': '689' }, statusCode: 200, status: 200, statusType: 2, info: false, ok: true, redirect: false, clientError: false, serverError: false, error: false, accepted: false, noContent: false, badRequest: false, unauthorized: false, notAcceptable: false, forbidden: false, notFound: false, type: 'text/html', setEncoding: [Function: bound ], redirects: [] }
Instamojo
Jan 25, 2017

body: { error: 'invalid_client' }

seems like the client_id or client_secret are wrong in the post request.
Please double check the data and ensure you use test credentials in test env and production credentials in production env.


Instamojo marked this as solved
Harshit Laddha
July 2, 2018

The Client ID is the same as the API Key on Production / Test integrations pages right ? Or is it something different ?

Markdown is allowed