5

I'm trying to synchronize user names and primary emails with AD via the Github API. I make a call to /user/emails using an oAuth token with scope user:email and I get back their primary email. I then try to use PATCH /user per this doc with the payload:

{
   email: newemail@ourcompany.com
}

And I get back a 404.

Is this the correct method to set the primary emails for users?

Richard Schaefer
  • 525
  • 3
  • 13
  • 45

3 Answers3

3

This is due to your API request is not properly authenticated or your OAuth token does not have the required scopes. As per your question, you have set user:email scope which does not allow modification of the profile. Use user scope intead.

Scopes in Githup API

See more: Why am I getting a 404 error on a repository that exists?

DinushaNT
  • 1,137
  • 6
  • 17
  • I'm calling admin/users with {"scopes": ["user:email"]} to get my OAuth token. I get the token and then call /user/emails with that token. I get back their email. I then call /user/patch with the payload above and the same OAuth token which is when I get the 404. I tried creating another OAuth token for the Patch call but that didn't help. – Richard Schaefer Dec 19 '19 at 16:11
  • 1
    @RichardSchaefer: According to the docs `"user:email"` does only [Grants **read** access to a user's email addresses.](https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/#available-scopes) – stovfl Dec 22 '19 at 09:44
  • @stovfl correct. I have updated the answer with your comment. – DinushaNT Dec 23 '19 at 11:18
  • @DinushaNT: Have you proven that ***"Use `user` scope"*** will be succesfull? Because the OP uses `PATCH /user` which is bound to *"Update the authenticated user"*. – stovfl Dec 23 '19 at 11:28
  • I was originally using just user but when that didn't work I tried user:email. I've not been able to get either to work. – Richard Schaefer Dec 23 '19 at 13:09
1

It requires authentication and it will return 404 Not Found, instead of 403 Forbidden, in some places. This is to prevent the accidental leakage of private repositories to unauthorized users.

You can try to make your email visibility to be public

[
  {
    "email": "newemail@ourcompany.com",
    "primary": true,
    "verified": true,
    "visibility": "public"
  }
]
I_Al-thamary
  • 3,385
  • 2
  • 24
  • 37
1

Turns out the issue was a typo in the PATCH URL.

Richard Schaefer
  • 525
  • 3
  • 13
  • 45