Created
September 28, 2017 16:23
-
-
Save alankimo/cc9e277ce4284edca163dfc4bade59d0 to your computer and use it in GitHub Desktop.
request_PUT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function updateCustomer($api_url, $api_key, $api_pswd, $customer_id, $billing_agreement, $tags_default) { | |
$baseUrl = "https://".$api_key.":".$api_pswd."@".$api_url."/admin/"; | |
$tagsFix = $tags_default . ', 20XX-' . $billing_agreement; | |
//Set up JSON payload | |
$payload = array( | |
"customer" => array( | |
'id' => $customer_id, | |
'tags' => $tagsFix | |
) | |
); | |
$payload = json_encode($payload, JSON_NUMERIC_CHECK); | |
$putUrl = $baseUrl."customers/".$customer_id.".json"; | |
$session = curl_init(); | |
curl_setopt($session, CURLOPT_URL, $putUrl); | |
curl_setopt($session, CURLOPT_CONNECTTIMEOUT, 30); //seconds to allow for connection | |
curl_setopt($session, CURLOPT_TIMEOUT, 30); //seconds to allow for cURL commands | |
curl_setopt($session, CURLOPT_HEADER, true); //include header info in return value ? | |
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); //return response as a string | |
//curl_setopt($session, CURLOPT_PUT, 1); | |
curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'PUT'); | |
curl_setopt($session, CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: PUT')); | |
curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); | |
curl_setopt($session, CURLOPT_POSTFIELDS, $payload); | |
$data = curl_exec($session); | |
curl_close($session); | |
return $data; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment