cURL in PHP
Using cURL is not recommended
Use a server-side SDK instead.
For PHP, you should use our server-side SDK for PHP. It's easy to use, and makes sure the requests you're sending are valid.
But if for whatever reason you prefer using cURL in PHP directly (e.g. you like pain ;-), there are a couple of things to keep in mind.
- There's no reason to set
CURLOPT_HTTP_VERSIONtoCURL_HTTP_VERSION_1_1. Just leave out that header. Our server supports HTTP/2. - If you do use HTTP/1.1, you'll need to make sure a
Content-Lengthheader is sent forPOSTrequests. cURL does that automatically if you set the request body throughCURLOPT_POSTFIELDS. Make sure to pass in an empty string when there's no request body - if not, cURL won't send theContent-Lengthheader! - It's absolutely necessary to check the response code of the call. In case of an error, you'll need to abort and notify your user, instead of assuming everything went fine.
Here's a complete example:
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "https://api-eu.seatsio.net/hold-tokens",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => '', // allow gzip, if your PHP supports it
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_USERPWD => "${secretWorkspaceKey}:"
]);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
if ($info['http_code'] < 200 || $info['http_code'] >= 300) {
throw new Exception("Call failed with error " . $info['http_code'] . ': ' . $result);
}
// ...