php - Postmate API not working -
i using postmates api book store. using test credentials, don't know how use it. kindly guide me how can make basic api call. using php. want send post data using curl thank you
<?php $url = "https://api.postmates.com/v1/customers/my-customer-key/delivery_quotes"; $uname = "my-api-key"; $pwd = null; $data = array( 'dropoff_address' => '20 mcallister st, san francisco, ca 94102', 'pickup_address' => '101 market st, san francisco, ca 94105', ); $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_httpheader, array('content-type: application/x-www-form-urlencoded')); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_httpauth, curlauth_basic); curl_setopt($ch, curlopt_userpwd, "$uname:$pwd"); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($process, curlopt_post, 1); curl_setopt($process, curlopt_postfields, $data); $output = curl_exec($ch); if (curl_errno($ch)) { echo 'error:' . curl_error($ch); } curl_close($ch); echo $output; ?>
from the documentation:
the postmates api requires authentication http basic auth headers. api key should included username. password should left empty.
this means need something following:
$curl = curl_init(); $url = "http://whatever-this-should-be"; curl_setopt($curl, curlopt_url, $url); $username = "your-api-key-goes-here"; $password = ""; // leave blank, per doc curl_setopt($curl, curlopt_userpwd, "$username:$password"); $res = curl_exec($curl);
you'll need tweak other curl options handle output, etc. core of you'll need.
you might want check out this library if want of @ higher (i.e. easier) level.
update: please aware sample code. wouldn't advocate storing api key in script file production code!
Comments
Post a Comment