Search code examples
restgithubgithub-api

Creating a Milestone for a Github Project via REST


I would like to use the REST API of Github to manage the milestones and labels of some of my repositories, but I constantly fail to create new milestones or labels via REST. What do I miss?

I enable 2FA for my account and also create a personal access token, as it is described in Other Authentication Methods

For example I try to create a new milestone with this cURL command:

curl -X POST -v \
  -H "Authorization: token MyPersonalAccessToken" \
  -H "Content-Type: application/json" \
  -H "Accept: application/vnd.github.v3+json" \
  -d '{"title": "1", "state": "open", "description": "Milestone", "due_on": "2025-10-09T23:39:01Z"}' \
  https://api.github.com/repos/obfischer/boxsack/milestones

I tried various other variants but all seems to be wrong. At least I always get only a 404 Not Found. According to the Github documentation this could also mean that my authentication failed, as Github returns a 404 Not Found response code to protect user data instead of returning a 401 Unauthorized.

But I am pretty sure that the authentication via the Person Access Token is working as I can see a user specific rate-limit headers in the response:

X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999

Does someone have a clue why I can't create a milestone via REST?


Solution

  • Maybe your personal access token doesn't have the repo scope. I've just tested to send the request with a token without that scope & it also returns 404 :

    < HTTP/1.1 404 Not Found
    < Date: Sat, 26 Oct 2019 11:07:31 GMT
    < Content-Type: application/json; charset=utf-8
    < Content-Length: 125
    < Server: GitHub.com
    < Status: 404 Not Found
    < X-RateLimit-Limit: 5000
    < X-RateLimit-Remaining: 4989
    < X-RateLimit-Reset: 1572091544
    < X-OAuth-Scopes: [Here there should be repo] <================
    < X-Accepted-OAuth-Scopes: 
    < X-GitHub-Media-Type: github.v3; format=json
    < Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type
    < Access-Control-Allow-Origin: *
    < Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
    < X-Frame-Options: deny
    < X-Content-Type-Options: nosniff
    < X-XSS-Protection: 1; mode=block
    < Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
    < Content-Security-Policy: default-src 'none'
    < X-GitHub-Request-Id: 87B2:23EED:36F2B7F:42647AE:5DB428F3
    < 
    {
      "message": "Not Found",
      "documentation_url": "https://developer.github.com/v3/issues/milestones/#create-a-milestone"
    }