cURL Create Prediction - Status 400 Bad Request Error Reading Body

Hi, I am looking for some help with the Create Prediction API and am having issues with the documented Curl. I am using the Twitch CLI as I don’t have partner access to the live system.

Firstly this is on the local host and I haven’t been able to test on live system.

Client_ID = 18d701582dfd7b433819ba79646edc
Client_Secret = afc4bc9ac797e8606796e3a888c62d
User_ID = 94542606

As API requirements I start with getting my access token using the following:

curl -X POST ‘http://localhost:8080/auth/authorize?client_id=18d701582dfd7b433819ba79646edc&client_secret=afc4bc9ac797e8606796e3a888c62d&grant_type=user_token&user_id=94542606&scope=channel:read:predictions%20channel:manage:predictions

Successful Response:

{
“access_token”: “57add02f7405337”,
“refresh_token”: “”,
“expires_in”: 86399,
“scope”: [“channel:read:predictions”, “channel:manage:predictions”],
“token_type”: “bearer”
}

Then POST the following attempting to create the prediction:

curl -X POST ‘http://localhost:8080/mock/predictions
-H ‘Authorization: Bearer 57add02f7405337’
-H ‘Client-Id: 18d701582dfd7b433819ba79646edc’
-H ‘Content-Type: application/json’
-d ‘{
“broadcaster_id”: “94542606”,
“title”: “Any leeks in the stream?”,
“outcomes”: [
{
“title”: “Yes, give it time.”
},
{
“title”: “Definitely not.”
}
],
“prediction_window”: 120,
}’

The Error Response on POST is

{
“status”: 400,
“error”: “Bad Request”,
“message”: “error reading body”
}

Can anyone spot where I am going wrong?

Unless it’s a copy paste fail

Your JSON contians the wrong kind of " (speechmarks) leading to a parse error

I’m going to test everything again by hand writing but I think the incorrect " is from highighting feature using this forums quotation thing.

Oh also if you leaked your real client secret, you should rotate it

If you copy/pasted the example from the docs. Which rechecking it seems to be.

It might be the , on the end of the payload (the prediction windonw beting 120, might be the invalidation as most JSON parsers won’t like it. (So the docs have an error)

Filed as 617 Create Prediction - Example JSON invalid · Issue #617 · twitchdev/issues · GitHub

1 Like

Yep that is the issue, sorry I should of caught that myself. Really appreciate you checking it out for me. Getting an different invalid oath token now, so im still doing something wrong but its not a syntax mistake anymore.

This is off topic but in the CLI Mock-Api is there a way to create a new broadcaster and get their client/ secret. Or to lookup generated broadcasters? I think I’m having an issue cause I’m using a normal generated user.

I don’t use the CLI Mock-API so I don’t know

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.