1

I want to set a header for getting the token from flipkart. I dont know how to set a header in curl. My header should like

curl -u <appid>:<app-secret> https://sandbox-api.flipkart.net/oauth-service/oauth/token\?grant_type\=client_credentials\&scope=Seller_Api
Jinu P C
  • 3,146
  • 1
  • 20
  • 29

2 Answers2

2

It looks like you're trying to do HTTP basic authentication, or at least that's what the -u option of curl does when used alone like this.

In PHP you would set up basic authentication for a curl request like this, assuming $ch is your curl instance (which you can get with curl_init):

curl_setopt($ch, CURLOPT_USERPWD, 'appid:appsecret');

See the curl documentation on curl_setopt for more information.

tremby
  • 9,541
  • 4
  • 55
  • 74
2

In curl command you have to do like this,

curl -u your-app-id:your-app-token https://sandbox-api.flipkart.net/oauth-service/oauth/token\?grant_type\=client_credentials\&scope=Seller_Api

you will get the result like this on success,

{"access_token":"394b7d-418a-43f6-8fd5-e67aea2c4b","token_type":"bearer","expires_in":4657653,"scope":"Seller_Api"}

by using this token you can make further api call's like for example listing api,

curl -H "Authorization:Bearer your-access-token" -H "Content-Type: application/json" -d 'json-here-see-format-in-api-example' https://url-end-point-refer-api-docs

note: you have to create app id and secret in "https://sandbox-api.flipkart.net/oauth-register/login" for sandbox. Don't store the access token it will get expired in certain period of time.

link for api doc's - "https://seller.flipkart.com/api-docs/fmsapi_index.html"

Vignesh
  • 496
  • 1
  • 4
  • 13