Set outside collaborator to particular Repo within an Organization using REST API

Hello community,
I am interested in automating the process with organization access.
What I need in particular is to be able to add outside collaborators to specific repositories which are part of and organizations.
Currently I can do that by going to the repo settings.
Going trough the API docs the only thing I was able to do is:

  • add a member to an organization;
  • then convert this member to an outside collaborator which can only be done after accepting the invitation;
  • remove a member from an organization;

Going through the capabilities of the API we have few problems:

  • I can’t make someone a collaborator directly because I have to wait for him to accept his invitation. There are workarounds like periodically checking whether he is on the invitation list with a GET Request but this will require extra logic and adding the membership won’t be immediate.
  • I can’t add someone to the specific repository in the chosen organization. This means that I will make him a member, then I will convert him to an outside collaborator, but without him being added to specific repositories he will just lose access to everything.

Let me know if you need further information and thank you in advance!