githubgithub-apigithub-api-v3github-appgithub-projects

Is it possible to create a user project (V2) with a github app?


I am trying to create a projectV2 with Github's Graphql API, through a Github App, because they have deprecated their classical projects, and if you try to create a project in a repository that doesn't have one previously associated Github doesn't allow it. There's a workaround to do it anyways, but it's a workaround that's probably gonna be removed soon..

I cannot find any official docs/posts/discussions describing how to do this (effectively, at least) so if someone has a resource to offer, that would also be great.

when I try to do the following mutation with an app created just with this purpose in mind, with every permission enabled (it would not need every permission to add a project for sure), the API responds with an error of type: "FORBIDDEN" and message: "Resource not accessible by integration"

(sent to api.github.com/graphql, with a content type and an Authorization header)

mutation {
  createProjectV2(
    input: {title: "V2 project related to test repo created by a bot", ownerId: "MY_USER_ID", clientMutationId: ""}
  ) {
    __typename
    projectV2 {
      creator {
        login
        resourcePath
        ... on Bot {
          id
          login
        }
      }
      ...ProjectV2Fragment
    }
    clientMutationId
  }
}

fragment ProjectV2Fragment on ProjectV2 {
  title
  id
  creator {
    login
    __typename
    resourcePath
  }
}

If I try to do it authenticated as myself with a (classic) personal access token, I can create it without any problem, but when I try this with the authentication that I got from the github App it won't let me.

I know the auth of the Github App is valid because I can create projects related to the organization I used to create the bot.

Any ideas?


Solution

  • Well, after even talking with Github support team, that what I needed was to create a token using the device flow. After doing this, I was able to do so. I'll leave a reference to Github's instructions for it.