0

Can anyone help to get access token by using Flipkart app id and app secret.

We have tried with the code below:

<?php
$username='appid';
$password='appsecret';
$url='https://api.flipkart.net/oauth-service/oauth/token\?grant_type\=client_credentials\&scope=Seller_Api';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
$output = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);   //get status code
$info = curl_getinfo($ch);
curl_close($ch);

if(curl_errno($ch)){   
    echo 'Curl error: ' . curl_error($ch);
}
print_r($output);
echo $status_code;

But we get the error:

{"error":"invalid_grant","error_description":"Unauthorized grant type: client_credentials"} 400

theduck
  • 2,589
  • 13
  • 17
  • 23

3 Answers3

1

I ran through the same issue and after struggling for a couple of hours I went to my seller account and recreated my "Application Id" and "Application Secret". The only difference I made was I selected "self_access_application" instead of "third_party_application" this time and I was good to go. Please refer: https://nimb.ws/sziWmA

Hope this helps Thanks

1

You can try this code, i also faced the same issue.

    $url  = "https://api.flipkart.net/oauth-service/oauth/token?grant_type=client_credentials&scope=Seller_Api";
    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_USERPWD,  config('constants.flipkart.application_id').":".config('constants.flipkart.secret_key'));
    curl_setopt($curl, CURLOPT_URL,$url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    $result = curl_exec($curl);
    $token = json_decode($result,true);

    if(isset($token['access_token'])){
        $this->access_token = $token['access_token'];
    }
Jay Momaya
  • 1,831
  • 19
  • 32
0

you can try this it will be helpful python/odoo developer

def flipkart_token_generation(self):
    if not self.flipkart_sandbox_app_id or not self.flipkart_sandbox_cert_id:
        raise UserError(_("Flipkart: cannot fetch OAuth token without credentials."))
    else:
        url = "https://sandbox-api.flipkart.net/oauth-service/oauth/token"
        data = {'grant_type': 'client_credentials', 'scope': 'Seller_Api'}
        response_json = requests.get(url, params=data, auth=(self.flipkart_sandbox_app_id, self.flipkart_sandbox_cert_id)).json()
        self.env['ir.config_parameter'].sudo().set_param('flipkart_sandbox_token', response_json["access_token"])