RESTv3: How to get all Projects a PR is in?

I am trying to find a way to find all Projects that a PR has been added to. Looking at the PR and Issue docs, I don’t see any way to do this. The only way I can see that it would be possible would be to iterate through all the Project cards for every project looking for my PR, but that feels… bad.

Is there something I’m missing here? How can I get this info?

I’m not sure that you can get this information easily using the v3 API, but there is a direct connection from a Pull Request object to the Project Cards associated with it in the v4 GraphQL API. You may want to experiment with using that instead?

I’ve been trying to use the v4 API to do this now, but it doesn’t seem to work. Using a query like this, I can find the pull request and the labels on the pull requests, but not the projects.

query {
  node (id: "MDExOlB1bGxSZXF1ZXN0MTA2OTI1") {
    ... on PullRequest {
      title
      url
      labels (first: 50) {
        edges {
          node {
            name
          }
        }
      }
      projectCards (first: 50) {
        edges {
          node {
            id
            project {
              name
              state
            }
          }
        }
      }
    }
  }
}

The result I get back just has this

"projectCards": {
  "edges": [
    {
      "node": null
    }
  ]
}

I know for a fact that the pull request in question is in a project, but I seem entirely unable to get any data about it.

Never mind, I figured it out (at least partially). Apparently the access key I generated didn’t have the needed permissions to access projects owned by this org. This seems to cause the API to just return nothing in that spot with no useful message as to why.

Generating a new token with all permissions seems to work, but I would rather not do that for no reason. Is it documented anywhere which specific permission I need to access this specific information? None of the permission descriptions seem to have anything to do with projects or the orgs that own them.