ajthinking
ajthinking

Reputation: 4558

Delete github respository via API

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.

Upvotes: 4

Views: 1447

Answers (2)

user1497164
user1497164

Reputation: 141

You must generate a token which includes the delete_repo scope through this page: https://github.com/settings/tokens/new

Upvotes: 2

FranklinChen
FranklinChen

Reputation: 756

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

curl -u $user:$token -XDELETE "https://api.github.com/repos/$user/$repo"

Upvotes: 2

Related Questions