Mimoid
Mimoid

Reputation: 812

How to fetch templates repos from Github API?

I want to fetch all repos that are templates from my account. I tried to fetch single repo according to this https://docs.github.com/en/rest/reference/repos#get-a-repository and then filter the response by "is_template" key as it is described in the docs. The problem is don't get this field in the response, other values are alright. This is the request I do: https://api.github.com/repos/my-account/test I'm authenticated, i'm on my own account, I try to fetch my own repo.

Questions:

  1. Am I doing something wrong that I don't have "is_template" in the fetched repo?
  2. Is there other way to fetch only templates rather than filtering out all repos?

Upvotes: 0

Views: 865

Answers (1)

Brendan Forster
Brendan Forster

Reputation: 2718

I believe you need to opt-in with the preview header to receive the new is_template field on the response.

This curl request works for me:

$ curl -s -H "Accept: application/vnd.github.baptiste-preview+json" https://api.github.com/repos/octokit/octokit.net | grep "is_template"
  "is_template": false,

Whereas this one does not return any output:

 curl -s https://api.github.com/repos/octokit/octokit.net | grep "is_template"

Upvotes: 1

Related Questions