Skip to content

Instantly share code, notes, and snippets.

@MrCoffey
Created May 25, 2016 19:55
Show Gist options
  • Select an option

  • Save MrCoffey/932e1368e529af8a059cec13deebf053 to your computer and use it in GitHub Desktop.

Select an option

Save MrCoffey/932e1368e529af8a059cec13deebf053 to your computer and use it in GitHub Desktop.
Basic example of customer creation using PHP
<?php
// Get cURL resource
$ch = curl_init();
// Set url
curl_setopt($ch, CURLOPT_URL, 'https://sandbox.tpaga.co/api/customer');
// Set method
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
// Set options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Set headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Cookie: JSESSIONID=ED3C3B4C34725BF144ADFF8E38C15113; AWSELB=19318121126A5B69695188D35750824B17EAA247679C0BE61EC84A863B523B1F2C04D3AC8AD397392B7EFEA95389F12DF1D72AF05FFA3DC737CA146433315E44135A605A30",
"Authorization: Basic ZDEzZnI4bjd2aHZrdWNoM2xxMmRzNXFoam5kMnBkZDI6
",
"Content-Type: application/json; charset=utf-8",
]
);
// Create body
$json_array = [
"firstName" => "Jhon",
"lastName" => "Cena",
"gender" => "M",
"email" => "jhoncena@rocks.me",
"phone" => "5555555"
];
$body = json_encode($json_array);
// Set body
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
// Send the request & save response to $resp
$resp = curl_exec($ch);
if(!$resp) {
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
} else {
echo "Response HTTP Status Code : " . curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo "\nResponse HTTP Body : " . $resp;
}
// Close request to clear up some resources
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment