Adding User to Organisation


#1

Hi,

I’m trying to create an integration that can add or remove users from my organization. I’ve managed to authenticate correctly and can use the installation token to access the API.

However, when I try to add a member as follows, I get 403 Forbidden:

response = conn.put do |req|
  req.url "/organizations/#{organization_id}/memberships/#{username}"
  req.headers['Authorization'] = "Token #{token}"
  req.headers['Accept'] = 'application/vnd.github.machine-man-preview+json'
end

Any ideas on how to get this working?

One point of confusion is that docs on permissions say that the permissions for an Integration can cover PUT /organizations/:organization_id/memberships/:user (:write) — and I’ve set the Integration’s permissions to Read/Write for Members — which is what I’m trying to do. However, this endpoint isn’t listed in the list of endpoints for Integrations.

Any help would be hugely appreciated!


#2

Sorry for the delay in getting back to you on this, @robisenberg! I just had a look and as far as I can tell – that endpoint (PUT /organizations/:organization_id/memberships/:user) isn’t supported for Integrations yet. I’ve opened an internal issue so that we can consider supporting it or clarifying the docs. Thanks for pointing this out! :bow:


#3

Hey @izuzak. Thanks for replying! It’s good to know definitively that it’s not supported yet. I’d love for that support to be there, but understand it’s a decision that needs to be made.

I guess, until then, I have to go with the normal OAuth approach — that lets you add/remove, right?


#4

I guess, until then, I have to go with the normal OAuth approach — that lets you add/remove, right?

Yep, you should definitely be able to use that endpoint from an OAuth application. Hopefully it will be available for Integrations as well.

Thanks again for expressing interest in this :thumbsup:


#5

Hey @robisenberg – just wanted to let you know that the team made some changes and you should now be able to use that endpoint from Integrations (as you initially expected). Mind giving it a try and letting us know if it works or if you’re still seeing problems? :pray: Thanks again!


#6

Hey @izuzak. I’m absolutely thrilled that you and the team are trying to get this working! Thanks so much.

However, unfortunately I am now getting a 500 Internal Server error.

Here’s my Faraday response if that’s of any use:

#<Faraday::Response:0x007fc8409753c8
 @env=
  #<struct Faraday::Env
   method=:put,
   body=
    "{\"message\":\"Server Error\",\"documentation_url\":\"https://developer.github.com/v3/orgs/members/#add-or-update-organization-membership\"}",
   url=
    #<URI::HTTPS https://api.github.com/organizations/27998375/memberships/user-with-no-repos>,
   request=
    #<struct Faraday::RequestOptions
     params_encoder=nil,
     proxy=nil,
     bind=nil,
     timeout=nil,
     open_timeout=nil,
     boundary=nil,
     oauth=nil,
     context=nil>,
   request_headers=
    {"User-Agent"=>"Faraday v0.12.1",
     "Authorization"=>"<MY TOKEN>",
     "Accept"=>"application/vnd.github.machine-man-preview+json",
     "Content-Length"=>"0"},
   ssl=
    #<struct Faraday::SSLOptions
     verify=true,
     ca_file=nil,
     ca_path=nil,
     verify_mode=nil,
     cert_store=nil,
     client_cert=nil,
     client_key=nil,
     certificate=nil,
     private_key=nil,
     verify_depth=nil,
     version=nil>,
   parallel_manager=nil,
   params=nil,
   response=#<Faraday::Response:0x007fc8409753c8 ...>,
   response_headers=
    {"server"=>"GitHub.com",
     "date"=>"Fri, 12 May 2017 09:34:18 GMT",
     "content-type"=>"application/json; charset=utf-8",
     "content-length"=>"132",
     "connection"=>"close",
     "status"=>"500 Internal Server Error",
     "x-ratelimit-limit"=>"5000",
     "x-ratelimit-remaining"=>"4997",
     "x-ratelimit-reset"=>"1494584910",
     "x-github-media-type"=>"github.machine-man-preview; format=json",
     "access-control-expose-headers"=>
      "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval",
     "access-control-allow-origin"=>"*",
     "content-security-policy"=>"default-src 'none'",
     "strict-transport-security"=>
      "max-age=31536000; includeSubdomains; preload",
     "x-content-type-options"=>"nosniff",
     "x-frame-options"=>"deny",
     "x-xss-protection"=>"1; mode=block",
     "x-github-request-id"=>"ED05:4A1D:6D4997C:84782AB:5915819A"},
   status=500,
   reason_phrase="Internal Server Error">,
 @on_complete_callbacks=[]>

#7

Thanks for following up, @robisenberg – I’ll look for that exception internally and ask the team to take a look.


#8

Great! Thanks so much! :thumbsup:


#9

@robisenberg, sorry that was a bug on our side - can you try it again now?


#10

Hey @keavy — it works! Thanks so much… really has made my day. :smile:

Thanks for your (and the rest of the team’s) help.