phpcurlflipkart-api

Set a curl header for getting tokens


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

Solution

  • 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.