Skip to main content


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_VERSION to CURL_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-Length header is sent for POST requests. cURL does that automatically if you set the request body through CURLOPT_POSTFIELDS. Make sure to pass in an empty string when there's no request body - if not, cURL won't send the Content-Length header!
  • 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_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => '', // allow gzip, if your PHP supports it
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);

// ...