2 Replies - 338 Views - Last Post: 18 November 2019 - 05:55 AM Rate Topic: -----

#1 nancybaby101   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 19-July 19

How to send the value of API KEY and Secret in curl request in php

Posted 17 November 2019 - 11:27 PM

I have the following API CURL below

curl -u API_KEY:API_SECRET https://api.mysite/v1/test

please how do I set and send the value of API_KEY:API_SECRET in the curl request below

$link ="https://api.mysite/v1/test";
$curl=curl_init(); 
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_URL,$link);
curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt($curl, CURLOPT_HTTPHEADER, array("accept: application/json"));  
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,1);
//curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
$out = curl_exec($curl); 
curl_close($curl);
var_dump($out);






Is This A Good Question/Topic? 0
  • +

Replies To: How to send the value of API KEY and Secret in curl request in php

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4246
  • View blog
  • Posts: 13,461
  • Joined: 08-June 10

Re: How to send the value of API KEY and Secret in curl request in php

Posted 18 November 2019 - 05:54 AM

that depends on where in the http request the key is supposed to be (resp. how you authenticate against the API).

This post has been edited by Dormilich: 18 November 2019 - 06:01 AM

Was This Post Helpful? 0
  • +
  • -

#3 Ornstein   User is offline

  • D.I.C Head

Reputation: 32
  • View blog
  • Posts: 64
  • Joined: 13-May 15

Re: How to send the value of API KEY and Secret in curl request in php

Posted 18 November 2019 - 05:55 AM

At a guess, you'll want to use curl_setopt to set CURLOPT_USERNAME and CURLOPT_USERPWD - if your version of PHP/cURL supports it.

Alternatively, you could use CURLOPT_HTTPHEADER to set your own Authorization header. (I assume you'll need to do some reading on the specifics of HTTP authorization)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1