Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete github respository via API

Tags:

github

I want to delete a list of repositories using the github API. But I get the response:

{ "message": "Bad credentials", "documentation_url": "https://developer.github.com/v3" }

Steps to reproduce

First I created a personal access token here: https://github.com/settings/tokens

I made sure it had the scope delete_repo

enter image description here

Then, create a variable for my token export GITHUB_TOKEN=asasfsafaffafsafafsfs

Finally run this script:

#!/bin/bash

repos=(
    "my_username/test-1"
)

for i in "${repos[@]}"
do
   :
   curl -XDELETE -H 'Authorization: token $GITHUB_TOKEN' "https://api.github.com/repos/$i ";
done

Changing the header to 'Authorization: $GITHUB_TOKEN' gives

{ "message": "Must have admin rights to Repository.",
"documentation_url": "https://developer.github.com/v3/repos/#delete-a-repository" }

Searching the error and reading the provided link does not help me. How can I not have admin rights to my own repository (it's not in an org)? I have also tried checking everything in the personal access token generation page without effect.

like image 349
ajthinking Avatar asked Oct 17 '25 06:10

ajthinking


1 Answers

Use the command (plugging in user, token, and repo)

curl -u $user:$token -XDELETE "https://api.github.com/repos/$user/$repo"
like image 128
FranklinChen Avatar answered Oct 21 '25 00:10

FranklinChen