Set user access restriction api not working as expected #144350
Unanswered
JeniferAnthonysamy
asked this question in
API and Webhooks
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Select Topic Area
Question
Body
Hi,
I am trying to implement the Set user access restriction api for protected branches. I think I am sending the correct data type yet it gives me the below error.
Sample data:
const jsonData = {
owner: owner,
repo: repo.repoName,
branch: branch,
userAccessRestrictions: {
users: [
"username1",
"username2"
]
},
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
};
Error:
const error = new RequestError(toErrorMessage(data), status, {
^
RequestError [HttpError]: Invalid request.
For 'links/5/schema', {"userAccessRestrictions"=>{"users"=>["Jenifer Anthony Samy", "Jenkins"]}} is not an array. - https://docs.github.com/rest/branches/branch-protection#set-user-access-restrictions
Sample code snippet:
import { Octokit } from "@octokit/core";
const octokit = new Octokit({
auth: ${githubToken}
})
const jsonData = {
owner: owner,
repo: repo.repoName,
branch: branch,
userAccessRestrictions: {
users: [
"username1",
"username2"
]
},
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
};
const userAccessRestrictions = jsonData.userAccessRestrictions;
if (!Array.isArray(userAccessRestrictions.users)) {
throw new Error('The users key is not an array');
} else {
console.log('The users key is an array');
}
const repoTeamsResponse = await octokit.request('PUT /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users', jsonData);
Any thoughts is appreciated!
Beta Was this translation helpful? Give feedback.
All reactions