I'm working with a really basic cURL API. I haven't really worked with cURL before, so I'm doing my best to feel through things.
For the sake of this example, let's say that there are two values I can pass to the API: email and location.
Also, I have to use basic HTTP Authentication where the password is blank and the username is my API key.
To help you understand what I'm going for, this is the example provided to me in the API documentation:
$ curl -X POST https://therequestpath -u $API_KEY: \
--form email=myemailaddress \
--form location='mylocation' \
--form content-type=application/json
{"id":"750ea3d7"}
At this point I really don't quite understand what I'm doing, but this is the code I've come up with so far (it isn't throwing any PHP errors, but it isn't doing what I want, either):
$username = 'myapikey';
$password = '';
$host = 'https://therequestpath';
$data = array('email' => 'myemailaddress', 'location' => 'mylocation');
$process = curl_init($host);
curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_POSTFIELDS, $data);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($process);
curl_close($process);
I'm not sure if I'm failing at the HTTP Authentication, passing the email / location values, or both. Any help would be appreciated.
application/jsoncontent type instead ofapplication/xml?content-typein the command-line, butContent-Typein PHP. That can matter. And I also don't understand the last two lines of your command-line example - haven't you omitted a \ at the end of the fourth line?