10-13-2023 12:45
10-13-2023 12:45
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>
10-15-2023 21:08
10-15-2023 21:08
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
10-16-2023 12:26
10-16-2023 12:26
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.