needle icon indicating copy to clipboard operation
needle copied to clipboard

How to send a json representation of the data but with custom Accept header?

Open niks3089 opened this issue 5 years ago • 1 comments

I am doing a post to Github API which requires custom Accept header and json representation. This is what I have

    var options = {
        headers: {
            Authorization: 'token <token>',
            Accept: 'application/vnd.github.everest-preview+json'
        },
    }
    var data = {
        event_type: "autotest",
        client_payload: {"componentToRun": "app"}
    }
    try {
        const res = await needle("post", 'https://api.github.com/repos/myrepo/reponame/dispatches',
            data,  options);
    } catch(e) {
    }

If I set json: true in options, the accept header is changed to Application/Json which is not what I want. I simply want to send the data as json without it touching my headers.

niks3089 avatar Dec 07 '19 20:12 niks3089

In that case don't pass json: true and pass JSON.stringify(data) instead of data.

tomas avatar Dec 09 '19 01:12 tomas