I want to add GitHub users as collaborators of an organization repository using NodeJS octokit/rest library. The library and manually sent requests to GitHub API repond with HTTP 404 - Not Found, even if my user account has a valid access token with the necessary permissions.
I am trying to add GitHub users as collaborators of an organization repository, no matter if they are members of the organization itself.
My requesting user is authenticated through a personal access token with needed permissions.
I am using 'octokit/rest's repos.addCollaborators
function with organization name as owner, the repositoryname as repo and the username of the user to be added as username property of the parameter object. The octokit object uses my accounts access token for authentification. My user account is owner of the organization.
this.octokit = new Octokit({
auth: accessToken,
log: {
debug: (msg) => { logger.debug(`${msg}`); },
error: (msg) => { logger.error(`${msg}`); },
info: (msg) => { logger.info(`${msg}`); },
warn: (msg) => { logger.warn(`${msg}`); }
},
userAgent: process.env.APP_NAME
});
// ...
this.octokit.repos.addCollaborator({
owner: ownername,
repo: url[url.length - 1],
username
}).catch((msg) => {
logger.verbose(`Error message ${msg}`);
});
Regarding the documentation, I expect that an invite is sent to the user.
Unfortunately I get 404 Not Found.
The same happens when I use curl:
curl -u myUsername:token -X PUT https://api.github.com/repos/:organizationname/:reponame/collaborators/:collaboratorname?permission=push
The same behaviour appears when performing a membership request.