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;
}
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
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