Fetching content from the repository could be done like this:
curl -L \
-H 'Accept: application/vnd.github+json' \
-H 'Authorization: Bearer <TOKEN>' \
-H 'X-Github-Api-Version: 2022-11-28' \
https://api.github.com/repos/<OWNER>/<REPO>/contents/README.md
The respons will be an object and the actual data is held base64 encoded under a key named content
. Here is an example using php:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.github.com/repos/<OWNER>/<REPO>/contents/README.md");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: application/vnd.github+json',
'X-Github-Api-Version: 2022-11-28',
'Authorization: Bearer <TOKEN>',
]);
curl_setopt($ch, CURLOPT_USERAGENT, 'my-user-agent');
$response = curl_exec($ch);
$response = \json_decode($response);
$readmeContent = base64_decode($response->content);
The above assumes that this is a private repository, so if that is the case you will need to generate a new private access token and set the correct header. Of course you will also have to change the OWNER
and REPO
in the above example.