CLI Predictions

Hello, Been trying to figure out the structure for a post to create predictions. keep getting errors on the “request body not parsable” curious if anyone could give me a sample post to predictions.

Thanks,

Well what does the code look like you that you are doing?

This sounds like you’ve mixed up the POST request content-type’s

So in JS

    let payload = {
        broadcaster_id: user_id,
        title: 'my title here',
        outcomes: [ {title:"option a"}, { title: "option b"} ],
        prediction_window: 1800
    }

    let poll_resp = await fetch(
        'https://api.twitch.tv/helix/predictions',
        {
            method: 'POST',
            headers: {
                'Client-ID': client_id,
                'Authorization': `Bearer ${access_token}`,
                'Content-Type': 'application/json',
                'Accept': 'application/json'
            },
            body: JSON.stringify(payload)
        }
    );

example midly adjusted from my poll example, so has some poll references. But the logic is similar

twitch api post /predictions -q broadcaster_id=my_id_here -q title=‘EVIDENCE’ -q prediction_window=30 -b ‘{“outcomes”:[{“title”:“YES”},{“title”:“NO”}]}’

Just trying to do a post through cmd prompt. plan to make a batch file for starting predictions(unless i’m completely misunderstanding a lot, which is possible)

I’ve already configured twitch CLI with my id and secret. I’m on Windows.

curl -X POST “https://api.twitch.tv/helix/predictions” ^
-H “Authorization: Bearer USER_ACCESS_TOKEN” ^
-H “Client-Id: USER_ID” ^
-H “Content-Type: application/json” ^
-H “Accept: application/json” ^
-d “{^“broadcaster_id^”: ^“USER_ID^”, ^“title^”: ^“Any leeks in the stream?^”, ^“outcomes^”:[{^“title^”: ^“Yes, give it time.^” }, { ^“title^”: ^“Definitely not.^”}],^“prediction_window^”:120}”

have also tried using cURL, get the same response. Not super good with API’s if that’s not obvious.

If i could accomplish this either way, I should be able to make a .bat and run it right? (i understand tokens will expire just focusing on one thing at a time.)

This seems to be the wrong kind of " but not sure if thats a copy/paste fault or something else? (assuming ^ is the windows escape character for cmd/powershell of whichever you are using

curl -X POST "https://api.twitch.tv/helix/predictions" ^
-H "Authorization: Bearer _____" ^
-H "Client-Id: ______" ^
-H "Content-Type: application/json" ^
-d "{^"broadcaster_id^": ^"____^", ^"title^": ^"Any leeks in the stream?^", ^"outcomes^":[{^"title^": ^"Yes, give it time.^" }, { ^"title^": ^"Definitely not.^"}],^"prediction_window^": 120}" 

think it was a copy paste thing from notepad++, they look fine on ++.
image

and yes windows esc character, cmd prompt

Got IT!!!
imagep
had to separate the json into a separate file and post it that way.

Thanks for the Assistance Barry!