Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

400 error when trying to add subscriptions - PHP

I have been trying to create new subscriptions via PHP but it always returns a 400 bad request error. I have tried making the command manually and it works, but my php code doesn't work.

 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.fitbit.com/1/user/-/body/apiSubscriptions/3.json");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = array();
$headers[] = "Authorization: Bearer $access_token";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:'.curl_error($ch);
}
$response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $response_code;
}

Best Answer
0 Votes
3 REPLIES 3

Hi @rocketslay1,

 

Can you provide me with the error message you are seeing? The messaging may help identify what the issue is.

 

Hope to hear from you soon!

Best Answer
0 Votes

I am getting a '400 bad request - cloudflare' error.

Best Answer
0 Votes

I am also getting the same error

<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare</center>
</body>
</html>

Can somebody help here ? 

Best Answer
0 Votes