2

I use Postman to Create a gist and I added bearer token in the authorization Tab but it suppose to create a gist and return 201 Created instead it returns 200 OK and it doesn't create anything enter image description here

I have written in the request body the example mentioned at GitHub Docs to create a Gist

{
  "description": "Hello World Examples",
  "public": true,
  "files": {
    "hello_world.rb": {
      "content": "class HelloWorld\n   def initialize(name)\n      @name = name.capitalize\n   end\n   def sayHi\n      puts \"Hello !\"\n   end\nend\n\nhello = HelloWorld.new(\"World\")\nhello.sayHi"
    },
    "hello_world.py": {
      "content": "class HelloWorld:\n\n    def __init__(self, name):\n        self.name = name.capitalize()\n       \n    def sayHi(self):\n        print \"Hello \" + self.name + \"!\"\n\nhello = HelloWorld(\"world\")\nhello.sayHi()"
    },
    "hello_world_ruby.txt": {
      "content": "Run `ruby hello_world.rb` to print Hello World"
    },
    "hello_world_python.txt": {
      "content": "Run `python hello_world.py` to print Hello World"
    }
  }
}
rkosegi
  • 14,165
  • 5
  • 50
  • 83
  • Please post what you've tried as text, and use the image as supporting context. Are you using `Content-Type: application/json`? – windowsill Nov 21 '20 at 08:38

1 Answers1

1

https://docs.github.com/en/free-pro-team@latest/rest/reference/gists#create-a-gist

Authentication You can read public gists anonymously, but you must be signed into GitHub to create gists. To read or write gists on a user's behalf, you need the gist OAuth scope and a token. For more information, see "Scopes for OAuth Apps."

You should be authenticated else you will have only read access, thats why you are getting 200 instead of 201

Second Reason: you are using http instead of https

Use token generated from developer settings as oauth2 bearer:

enter image description here

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • Thanks for your answer , but I got a personal access token from developer settings at github with the scope gist , I think its enough to post requests, if there any other way to get other type of token please clarify it? @PDHide – Deena M. Zamzam Nov 22 '20 at 01:09
  • Accept: application/vnd.github.v3+json are you setting this header ? remove the default accept header from postman and add this . ALso try using multiform data instead of json body to send this and see – PDHide Nov 22 '20 at 01:44
  • @DeenaM.Zamzam for me its working please see the updated answer you can use body as raw>json . When you add authorization use oauth 2 , bearer token . ALso use https instead of http – PDHide Nov 22 '20 at 01:55
  • @DeenaM.Zamzam ussing https instead of http will fix your issue if you are passing auth token as bearer , and accept as application/vnd.github.v3+json – PDHide Nov 22 '20 at 01:57
  • Thanks a million you are genius it was the s in https @PDHide – Deena M. Zamzam Nov 22 '20 at 09:14
  • @DeenaM.Zamzam please accept the anser and upvote by clicking the up arrow and tick sign near my answer :) – PDHide Nov 22 '20 at 10:06