I’m getting error:
{
"message":"Not Found",
"documentation_url":"https://docs.github.com/rest",
"status":"404"
}
when trying to create private repo on my GitHub account. My code in php:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.github.com/MY_USERNAME/repos',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
"Accept: application/vnd.github+json",
"Authorization: Bearer MY_TOKEN",
"X-GitHub-Api-Version: 2022-11-28",
"User-Agent: MY_APP_NAME"
),
CURLOPT_POSTFIELDS => array(
"name" => "test-repo-123",
"description" => "This is your first repo!",
"homepage" => "https://MY_URL",
"private" => true,
"is_template" => true
),
));
$response = curl_exec($curl);
curl_close($curl);
I had to create GH App, and installed it on my GH Account.
When I cut line:
"User-Agent: MY_APP_NAME"
I get error:
Request forbidden by administrative rules. Please make sure your request has a User-Agent header (https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required). Check https://developer.github.com for other possible causes.
Ofcourse, in constants: MY_USERNAME, MY_TOKEN, MY_APP_NAME, MY_URL I have my sensitive data.
What am I doing wrong?
Thanks
Mike