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

Curl to create API subscriptions failing with 400 Bad Request

I am trying to create a subscription. I have verified my subscription API. I am using this curl given in documentation here to create a new subscription, but it is failing with 400 Bad request. Please help

Curl command

curl -X POST "https://api.fitbit.com/1/user/-/body/apiSubscriptions/9pgqWLScRzNuJ8C5HZwp4WizuG92.json" \
-H "accept: application/json" \
-H "Authorization: Bearer <a valid token>" \
-H "content-length: 10000"

This is the response 

<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare</center>
</body>
</html>
Best Answer
0 Votes
2 REPLIES 2

I figured it out the content-length value needs to be 0 because we are not sending any content with this post request. Bad API design IMO

Best Answer
0 Votes

Hi @genepathdx_dev 

According to RFC 7230, section 3.3.2, the POST HTTP requests requires the Content-Length header field containing the anticipated size of the payload body.  The subscription endpoint does not have a payload body, therefore the size is 0 (zero).  The API is designed correctly.

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes