I have below cURL:

curl https://api.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "<Client-Id>:<Secret>" \
-d "grant_type=client_credentials".

I want it to be in Http request model as below :

 req.setBody('grant_type=client_credentials&<Client-Id>:<Secret>');   //replaced clientid and secret with the values from sandbox.

But i am getting below code as response : HttpResponse[Status=Not Acceptable, StatusCode=406]

Can any one point me what was the issue.

2 Answers 2


As far as I can tell a 406 response most likely indicates you are missing a supported Accept header.

There are some parts missing from what I can see of your Apex code.

In cURL, the -H option sets a header. You will need to use the corresponding setHeader(key, value) method in Apex to set the Accept and Accept-Language headers.

The -u header sets the user name and password for server authentication. The -d header sets the post request body.

These two have been merged in your example. I'm not sure if you can just append the authentication details onto the request body like that. I suspect you will need to use a named credential when setting the endpoint.

The older question Basic Http Authentication has an example of how to manually set the header to correspond to the -u option:

Blob headerValue = Blob.valueOf(clientId +':' +password);
String authorizationHeader = 'Basic ' + 'EncodingUtil.base64Encode(headerValue);
system.debug('Encoder Value' + EncodingUtil.base64Encode(headerValue));
req.setHeader('Authorization', authorizationHeader);
  • So what should we use for -u Header for Http Request. Like -H can be taken as req.setHeader(key,value);
    – sunny
    Jul 7, 2015 at 9:33
  • @sunny It looks like you can manually base64 encode the authentication details and use them to set the Authorization header. I slightly modified the example from the linked question to suit your needs. Jul 7, 2015 at 9:41

You need to set basic authorization header like below, also i have added missing headers.

 Blob headerValue = Blob.valueOf(<Client-Id>+':'+<Secret>);
 String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
 req.setHeader('Authorization', authorizationHeader);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .