OAuth token is missing but token is added to the header

I’m trying to make an API request to ban a user but I’m getting this error:

data: {
      error: 'Unauthorized',
      status: 401,
      message: 'OAuth token is missing'
}

This is my code:

const response = await axios.post(`https://api.twitch.tv/helix/moderation/bans?broadcaster_id=${channelId}&user_id=${userId}&moderator_id=${moderatorId}`, {
    headers: {
        "Client-ID": `<client-id>`,
        "Authorization": `Bearer <access-token>`,
        "Content-Type": "application/json"
    }
})

I believe with axios post, argument 2 is for the POST body and argument 3 is where options such as headers go

https://axios-http.com/docs/post_example

Your problem is a axios.post usage issue not an API issue.

You’ve posted your headers as HTTP POST body in error

I have corrected it and now I get this error:

data: {
      error: 'Bad Request',
      status: 400,
      message: 'Missing required parameter "user_id"'
}

You declared a content-type of JSON then didn’t post any JSON

Twitch ignored the params on the query string as you said you were sending JSON

So I just have to remove that line?

Or POST a JSON body

Something like this?

const data = {
    "broadcaster_id": channelId,
    "user_id": userId,
    "moderator_id": moderatorId
}

const response = await axios.post(`https://api.twitch.tv/helix/moderation/bans`, data, {
    headers: {
        "Client-ID": `<client-id>`,
        "Authorization": `Bearer <access-token>`,
        "Content-Type": "application/json"
    }
})
const data = JSON.stringify({
    "broadcaster_id": channelId,
    "user_id": userId,
    "moderator_id": moderatorId
});

thats if axios won’t JSON for you

It seems I’m really bad at this. I keep getting the same error both ways. Maybe it would be better if I show you the whole function?

This is my function for banning a user, using fetch rather than axios

Thank you so much!