I am trying to automate the configuration of a Github Enterprise. This ofcourse starts with the organizations. Github has a REST API for this.
Whenever I run the script with secrets.GITHUB_TOKEN I get the error: “Resource not accessible by integration”. 403
If I run the script with a fine grained pat with full permissions I get the error: “Not Found” 404
I am running this script from in a repository in an organization in the Enterprise where I am trying to make a new organization. Code below.
name: Config Enterprise
permissions:
write-all
on:
push:
branches:
- main
jobs:
my-action:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm install @octokit/action
- run: node .github/actions/createORG.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN}}
const { Octokit } = require("@octokit/core");
const octokit = new Octokit({
authorization: `token ${process.env.GITHUB_TOKEN}`
})
async function createORG(orgUserName, orgDisplayName, admin) {
try {
await octokit.request('POST /admin/organizations', {
login: orgUserName,
profile_name: orgDisplayName,
admin: admin,
headers: {
authorization: `token ${process.env.GITHUB_TOKEN}`,
'X-GitHub-Api-Version': '2022-11-28'
}
});
console.log("Created organization");
} catch (error) {
console.error("Error:", error);
}
}
createORG('DLW-TEST2-EMRE', 'DLW-TEST2-EMRE', 'igtene_dlwr')