Login issue with API for getting access token



  • Hi I am getting the following error to get access token after redirection

    {"code":400,"status":"Bad Request","timestamp":"2017-07-09T03:06:59+05:30","error":{"reason":"Required field 'grant_type' is missing"}}

    But I am passing all the required fields & passing this grant_type as well.

    So please help to fix this issue



  • @TRADERAYS - Can you please send me your API request details - Request body, Authorization headers value and API key on support@upstox.com, I will check at my end and try to resolve this issue ASAP.

    Thanks



  • Hi @RenukaMisal , please find the request and response details below for accessing the token using upstox api.

    REQUEST

    [2017-07-10 20:00:34,088] - [DEBUG] [wire] - http-outgoing-0 >> "POST /index/oauth/token?grant%255Ftype=authorization%255Fcode&redirect%255Furi=http%3A%2F%2Flocalhost%3A8080%2Fats%2Fupstox-auth&code=ea1b093f29e34ab9285adc7d78535130f6fe1cf0&apiSecret=6ewinvjvj3 HTTP/1.1[\r][\n]"
    [2017-07-10 20:00:34,088] - [DEBUG] [wire] - http-outgoing-0 >> "accept: application/json[\r][\n]"
    [2017-07-10 20:00:34,088] - [DEBUG] [wire] - http-outgoing-0 >> "accept-encoding: gzip[\r][\n]"
    [2017-07-10 20:00:34,088] - [DEBUG] [wire] - http-outgoing-0 >> "Authorization: Basic Mk1SM2drOURFMzNDOWJvUmVYbjljM2dwQ1llRkI5eGY3NjNmbGJESjo2ZXdpbnZqdmoz[\r][\n]"
    [2017-07-10 20:00:34,088] - [DEBUG] [wire] - http-outgoing-0 >> "Content-Type: application/json[\r][\n]"
    [2017-07-10 20:00:34,089] - [DEBUG] [wire] - http-outgoing-0 >> "user-agent: unirest-java/1.3.11[\r][\n]"
    [2017-07-10 20:00:34,089] - [DEBUG] [wire] - http-outgoing-0 >> "Content-Length: 0[\r][\n]"
    [2017-07-10 20:00:34,089] - [DEBUG] [wire] - http-outgoing-0 >> "Host: api.upstox.com[\r][\n]"
    [2017-07-10 20:00:34,089] - [DEBUG] [wire] - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
    [2017-07-10 20:00:34,089] - [DEBUG] [wire] - http-outgoing-0 >> "[\r][\n]"

    RESPONSE

    [2017-07-10 20:00:34,281] - [DEBUG] [wire] - http-outgoing-0 << "HTTP/1.1 401 Unauthorized[\r][\n]"
    [2017-07-10 20:00:34,283] - [DEBUG] [wire] - http-outgoing-0 << "Content-Type: application/json[\r][\n]"
    [2017-07-10 20:00:34,284] - [DEBUG] [wire] - http-outgoing-0 << "Content-Length: 135[\r][\n]"
    [2017-07-10 20:00:34,284] - [DEBUG] [wire] - http-outgoing-0 << "Connection: keep-alive[\r][\n]"
    [2017-07-10 20:00:34,284] - [DEBUG] [wire] - http-outgoing-0 << "Date: Mon, 10 Jul 2017 14:30:31 GMT[\r][\n]"
    [2017-07-10 20:00:34,284] - [DEBUG] [wire] - http-outgoing-0 << "x-amzn-RequestId: 54067996-657c-11e7-8e48-71837ce3fd06[\r][\n]"
    [2017-07-10 20:00:34,284] - [DEBUG] [wire] - http-outgoing-0 << "X-Amzn-Trace-Id: Root=1-59638f87-617238dd8c62ed5a60007284[\r][\n]"
    [2017-07-10 20:00:34,284] - [DEBUG] [wire] - http-outgoing-0 << "X-Cache: Error from cloudfront[\r][\n]"
    [2017-07-10 20:00:34,285] - [DEBUG] [wire] - http-outgoing-0 << "Via: 1.1 16cfccb6d55cfe3498d5cf79893ff28d.cloudfront.net (CloudFront)[\r][\n]"
    [2017-07-10 20:00:34,285] - [DEBUG] [wire] - http-outgoing-0 << "X-Amz-Cf-Id: cL-hd5nEh8OZVyEUcdJxJrn8pIUyfn0UVYG-vwjo9zq18JG02bIJCQ==[\r][\n]"
    [2017-07-10 20:00:34,285] - [DEBUG] [wire] - http-outgoing-0 << "[\r][\n]"
    [2017-07-10 20:00:34,285] - [DEBUG] [wire] - http-outgoing-0 << "{"code":400,"status":"Bad Request","timestamp":"2017-07-10T20:00:31+05:30","error":{"reason":"Required field 'grant_type' is missing"}}"

    Please help to fix this issue asap.



  • @RenukaMisal : plz find the today test request & response

    [2017-07-11 21:00:53,046] - [DEBUG] [wire] - http-outgoing-0 >> "POST /index/oauth/token?grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fats%2Fupstox-auth&code=fee53d19e96ba27eac220842e5bee393492f8d58&apiSecret=6ewinvjvj3 HTTP/1.1[\r][\n]"
    [2017-07-11 21:00:53,046] - [DEBUG] [wire] - http-outgoing-0 >> "accept: application/json[\r][\n]"
    [2017-07-11 21:00:53,046] - [DEBUG] [wire] - http-outgoing-0 >> "accept-encoding: gzip[\r][\n]"
    [2017-07-11 21:00:53,046] - [DEBUG] [wire] - http-outgoing-0 >> "Authorization: Basic Mk1SM2drOURFMzNDOWJvUmVYbjljM2dwQ1llRkI5eGY3NjNmbGJESjo2ZXdpbnZqdmoz[\r][\n]"
    [2017-07-11 21:00:53,046] - [DEBUG] [wire] - http-outgoing-0 >> "Content-Type: application/json[\r][\n]"
    [2017-07-11 21:00:53,046] - [DEBUG] [wire] - http-outgoing-0 >> "user-agent: unirest-java/1.3.11[\r][\n]"
    [2017-07-11 21:00:53,046] - [DEBUG] [wire] - http-outgoing-0 >> "Content-Length: 0[\r][\n]"
    [2017-07-11 21:00:53,046] - [DEBUG] [wire] - http-outgoing-0 >> "Host: api.upstox.com[\r][\n]"
    [2017-07-11 21:00:53,046] - [DEBUG] [wire] - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"

    [2017-07-11 21:00:53,242] - [DEBUG] [wire] - http-outgoing-0 << "HTTP/1.1 401 Unauthorized[\r][\n]"
    [2017-07-11 21:00:53,242] - [DEBUG] [wire] - http-outgoing-0 << "Content-Type: application/json[\r][\n]"
    [2017-07-11 21:00:53,242] - [DEBUG] [wire] - http-outgoing-0 << "Content-Length: 135[\r][\n]"
    [2017-07-11 21:00:53,242] - [DEBUG] [wire] - http-outgoing-0 << "Connection: keep-alive[\r][\n]"
    [2017-07-11 21:00:53,242] - [DEBUG] [wire] - http-outgoing-0 << "Date: Tue, 11 Jul 2017 15:30:50 GMT[\r][\n]"
    [2017-07-11 21:00:53,242] - [DEBUG] [wire] - http-outgoing-0 << "x-amzn-RequestId: eb5683d7-664d-11e7-b509-2bb838dca358[\r][\n]"
    [2017-07-11 21:00:53,242] - [DEBUG] [wire] - http-outgoing-0 << "X-Amzn-Trace-Id: Root=1-5964ef2a-dcd9a86613b8d012a7766a84[\r][\n]"
    [2017-07-11 21:00:53,243] - [DEBUG] [wire] - http-outgoing-0 << "X-Cache: Error from cloudfront[\r][\n]"
    [2017-07-11 21:00:53,243] - [DEBUG] [wire] - http-outgoing-0 << "Via: 1.1 12411872143fa5c1824f04f80a642e99.cloudfront.net (CloudFront)[\r][\n]"
    [2017-07-11 21:00:53,243] - [DEBUG] [wire] - http-outgoing-0 << "X-Amz-Cf-Id: CMtpFYruYIOBBP8vofBZG7tvjVsH9VviYSRpLW5WD8PvE_9oCODFNA==[\r][\n]"
    [2017-07-11 21:00:53,243] - [DEBUG] [wire] - http-outgoing-0 << "[\r][\n]"
    [2017-07-11 21:00:53,243] - [DEBUG] [wire] - http-outgoing-0 << "{"code":400,"status":"Bad Request","timestamp":"2017-07-11T21:00:50+05:30","error":{"reason":"Required field 'grant_type' is missing"}}"



  • @TRADERAYS - The API requires all the parameters in post body in the JSON format.
    body:
    { code: your code value,
    grant_type: 'authorization_code',
    redirect_uri: your redirect url
    }

    Please check the below link for curl command: https://upstox.com/developer/api/v1/docs/?shell#authorization



  • Now with new document update, we are get access token successfully.

    Thank you @RenukaMisal


Log in to reply
 

Looks like your connection to Upstox Forum was lost, please wait while we try to reconnect.