Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

338
Visualizações
Getting the subject_id for the subject_type GitHub User API

Using the GitHub API via Octokit.js and looking at the docs for getContextForUser (https://docs.github.com/en/rest/users/users#get-contextual-information-for-a-user), it mentions that when specifying the subject_type you also need to specify the subject_id. For the subject_id, it states, "Uses the ID for the subject_type you specified."

I have no idea where you get the relevant subject_id for the subject_type. I have searched high and low but with no success. Does anybody know where one can find a map that shows the ID for a subject_type?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The subject_id is the ID of the thing you want to have information about. For example, if you want to have information about a repository (in this case the subject type), you'd have to pass the ID of the repository you want to have information about.

In my opinion, it's a bit confusing that the API docs say this must be a string, while it is typically a numeric ID.

Repository Sample

Let's take a look at an example: Say we want to know what Torvald's hovercard on the repository torvalds/linux is. First, we need to get the ID of the repository:

> curl https://api.github.com/repos/torvalds/linux
{
  "id": 2325298,
# ...

With this ID, we can query the subject type repository:

> curl "https://api.github.com/users/torvalds/hovercard?subject_type=repository&subject_id=2325298"
{
  "contexts": [
    {
      "message": "Owns this repository",
      "octicon": "repo"
    },
    {
      "message": "Committed to this repository in the past day",
      "octicon": "git-commit"
    }
  ]
}

Pull Request Sample

Similarly, you can fetch the ID of pull request.

You need to be careful which ID you're using though: While pull request within a repository are identified with a typically small number (the one you see in the URL), the API in question does not have context of the repository, so you need to pass the global ID.

> curl "https://api.github.com/repos/torvalds/linux/pulls/486"
{
  "url": "https://api.github.com/repos/torvalds/linux/pulls/486",
  "id": 150630598,
# ...

And then use the subject type pull_request to fetch Linus' role in it:

curl "https://api.github.com/users/torvalds/hovercard?subject_type=pull_request&subject_id=150630598"
{
  "contexts": [
    {
      "message": "Owns this repository",
      "octicon": "repo"
    },
    {
      "message": "Committed to this repository in the past day",
      "octicon": "git-commit"
    }
  ]
}

Note that the endpoint to fetch contextual information requires authentication so you'll have to add a header to the curl samples.

If you're frequently experimenting with the GitHub API, I recommend installing the GitHub CLI, because it allows you to run authenticated queries like so:

> gh api /repos/torvals/linux
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda