Skip to content

Instantly share code, notes, and snippets.

@alankimo
Created September 28, 2017 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alankimo/cc9e277ce4284edca163dfc4bade59d0 to your computer and use it in GitHub Desktop.
Save alankimo/cc9e277ce4284edca163dfc4bade59d0 to your computer and use it in GitHub Desktop.
request_PUT
<?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