1

how can I combine ApiKey with Basic Authentication? The API requires to pass ApiKeyby extending the Basic Auth Headers. Actualy pass 2 more headers in basic auth (apiVersion & apiKey)

The manual has the following example (cURL command line)

curl --basic \
    -u "apiVersion=1;apiKey=myapikey;usename:password" \
    -H 'Content-Type: application/json' \
    -i http://someapi.com/rest/getdata?id=123

How can I do that with PHP cURL?

Thanks

1

1 Answer 1

1

Kindly read the documentation:

//for starting curl
$ch = curl_init();

//url to send request
curl_setopt($ch, CURLOPT_URL, 'http://someapi.com/rest/getdata?id=123');

//return results
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//post/get method
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

//for -u authorisation
curl_setopt($ch, CURLOPT_USERPWD, 'apiVersion=1;apiKey=myapikey;usename' . ':' . 'password');

//for -H headers
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

//execution and results    
$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.