Making a POST request to create custom rewards

Hi there!
First time posting on this forum, however been using it a lot recently.

I am trying to create a custom points reward programmatically(need to be able to refund points using my application)

I am already using OAuth token for reading information about rewards redeemed(so it is not expired) and have been using a valid client ID as well

    let url = "https://api.twitch.tv/helix/channel_points/custom_rewards?broadcaster_id=" + channelID;
    let authToken = authenticationToken;
    let clientID = clientId;

    //creating normal attack reward
    $.ajax({
        url: url,
        method: "POST",
        headers: {
            "Client-ID": clientID,
            "Authorization": "OAuth " + authToken
        },
        data: {
            "title": "Attack",
            "cost": 30
        } }).done(function(user) {
            console.log("Attack rewards was created");
        });

Have been using this code to send the request and I get a 401 error back

I assume it might be one of two issues
→ the broadcaster_id at the end of the URL (that is my channel ID that I entered)
→ the data attached to the POST request (I could not find an example of post request with data, so am unsure if I am doing it correctly)

That’s not the correct way to send an OAuth token, it should be

"Authorization": "Bearer " + authToken

1 Like

I have updated my code, however I still get the same error

Also, could you advise on how do I deal with the changes I make to the code in the process of pinpointing the issue?
Should I edit my original post’s code or just leave it as it is?

Thank you for helping, highly appreciated!

Is the authentication token you are using of type user for the channel channelID with the correct scopes applies?

Whats the body message?

The HTTP Code is only half the information. The body will describe the problem

1 Like

Hi Barry!
Thank you very much, your advice helped me resolve the issue.
I am quite a newb in web development and I did not know how to debug errors(looking at the body message of the response)
The only issue with my code was what @Dist suggested and the error I was getting after changing that line was because of creation of a duplicate reward

Have a wonderful day, thank you once again!

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