why Github gist API is throwing 400 error?

Viewed 139

I'm trying to use Github Gist API to create a gist. The code is shown below:

var result = {
  'a.md':'aaa',
  'b.md':'bbb',
}
/*
P.S. I also tried this, but it doesn't work, either

var result = {
  'a.md' :{
    content: 'aaa',
  },
  'b.md': {
    content: 'bbb',
  },
}
*/
$.ajax({
  type: "POST",
  url: 'https://api.github.com/gists',
  headers: {
    accept: "application/vnd.github.v3+json",
    Authorization: `token ${TOKEN}`,
  },
  data: {
    files: result,
    description: 'demo',
    public: false,
  },
  success: (response) => {
    console.log(response);
  },
});

but I received an error: POST https://api.github.com/gists 400 (Bad Request).

the request is:

{
  "message": "Problems parsing JSON",
  "documentation_url": "https://developer.github.com/v3/gists/#create-a-gist"
}

And I wonder why and how to fix it.

(This is not English native speaking, so don't mind my grammar mistakes)

0 Answers
Related