Cannot generate installation access token even though installation id is correct

I’m confused as to why I cannot generate an installation access token.  See the below two commands:

> curl -i -H "Authorization: Bearer <JWT> -H "Accept: application/vnd.github.machine-man-preview+json" https://api.github.com/app/installations/754036


{
"id": 754036,
"account": {
"login": "hamelsmu",
"id": 1483922,
"node_id": "MDQ6VXNlcjE0ODM5MjI=",
"avatar_url": "https://avatars2.githubusercontent.com/u/1483922?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hamelsmu",
"html_url": "https://github.com/hamelsmu",
"followers_url": "https://api.github.com/users/hamelsmu/followers",
"following_url": "https://api.github.com/users/hamelsmu/following{/other_user}",
"gists_url": "https://api.github.com/users/hamelsmu/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hamelsmu/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hamelsmu/subscriptions",
"organizations_url": "https://api.github.com/users/hamelsmu/orgs",
"repos_url": "https://api.github.com/users/hamelsmu/repos",
"events_url": "https://api.github.com/users/hamelsmu/events{/privacy}",
"received_events_url": "https://api.github.com/users/hamelsmu/received_events",
"type": "User",
"site_admin": true
},
"repository_selection": "selected",
"access_tokens_url": "https://api.github.com/installations/754036/access_tokens",
"repositories_url": "https://api.github.com/installation/repositories",
"html_url": "https://github.com/settings/installations/754036",
"app_id": 27079,
"target_id": 1483922,
"target_type": "User",
"permissions": {
"issues": "write",
"pull_requests": "write",
"app_config": "read",
"checks": "read",
"contents": "read",
"metadata": "read"
},
"events": [
"issues",
"project",
"project_card",
"project_column",
"pull_request",
"pull_request_review",
"pull_request_review_comment"
],
"created_at": "2019-03-16T04:57:54.000Z",
"updated_at": "2019-03-16T17:03:35.000Z",
"single_file_name": null
}

However when I add _ access_tokens _ to the end of the url it returns the following:

> curl -i -H "Authorization: Bearer <JWT>" -H "Accept: application/vnd.github.machine-man-preview+json" https://api.github.com/app/installations/754036/access_tokens

HTTP/1.1 404 Not Found
Date: Sun, 17 Mar 2019 05:20:25 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 87
Server: GitHub.com
Status: 404 Not Found
X-GitHub-Media-Type: github.machine-man-preview; 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: C82A:9BB9:1AA2AFF:207EC5B:5C8DD919

{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3"
}

Does anyone have any idea about this?

Thank you for being here! Could you please send us the full output of a curl -v request that demonstrates the problem?

http://curl.haxx.se/

That should help us investigate the issue. Also, please make sure you mask any sensitive information like OAuth tokens and Authorization headers in the output of the curl command. Please send the output to https://github.com/contact. And include a link to this thread to give support some background on the ticket.

I hope this helps!

Best,
Andrea

This issue was solved because I made a mistake in the request, 

the /access_tokens endpoint should be accessed via a POST request, and I was using GET.  Per the documentation, this is done with 

curl -i -X POST \
-H "Authorization: Bearer YOUR_JWT" \
-H "Accept: application/vnd.github.machine-man-preview+json" \
https://api.github.com/app/installations/:installation_id/access_tokens

I just didn’t see the POST part when I was reading it.  Thanks

2 Likes

Thanks so much, @hamelsmu for coming back to share what worked!

0ece40fa59d76e4cf889cc2099d43cf6.jpg

##"""—><>>application/vnd.github.machine-man-preview+json <curl -i -X POST \
-H “Authorization: Bearer YOUR_JWT” \
-H “Accept: application/vnd.github.machine-man-preview+json” \
https://api.github.com/app/installations/:installation_id/access_tokens>>""

@hamelsmu wrote:

This issue was solved because I made a mistake in the request, 

 

the /access_tokens endpoint should be accessed via a POST request, and I was using GET.  Per the documentation, this is done with 

 

curl -i -X POST
-H “Authorization: Bearer YOUR_JWT”
-H “Accept: application/vnd.github.machine-man-preview+json”
https://api.github.com/app/installations/:installation_id/access_tokens

I just didn’t see the POST part when I was reading it.  Thanks

@hamelsmu wrote:

This issue was solved because I made a mistake in the request, 

 

the /access_tokens endpoint should be accessed via a POST request, and I was using GET.  Per the documentation, this is done with 

 

curl -i -X POST
-H “Authorization: Bearer YOUR_JWT”
-H “Accept: application/vnd.github.machine-man-preview+json”
https://api.github.com/app/installations/:installation_id/access_tokens

I just didn’t see the POST part when I was reading it.  Thanks