Search code examples
restgithublabelgithub-api

Rename a label on Github with curl


I'm trying to rename a label on Github with the REST API. I can read the label

curl https://api.github.com/repos/adamschmideg/label-cleanup/labels/question

and it returns a nice json.

However when I try to update it following the doc on Updating a Github issue label and execute this

curl \
    --request PATCH \
    https://api.github.com/repos/adamschmideg/label-cleanup/labels/question \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{\"name\": \"just-a-question\"}"

it returns a message "Not found". It returns the same message for a non-existant label.

What am I getting wrong?


Solution

  • This appears to be a public repository which means anybody can see its labels.

    However, updating a label is restricted. You need to authenticate, e.g. by adding -u "username" to your request for basic authentication:

    curl \
        -u "adamschmideg" \  # <-- Right here
        --request PATCH \
        https://api.github.com/repos/adamschmideg/label-cleanup/labels/question \
        --header "Content-Type: application/json" \
        --header "Accept: application/json" \
        --data "{\"name\": \"just-a-question\"}"
    

    If you're using two-factor authentication and you want to use basic authentication as shown here you'll need to include a one-time code in a special X-GitHub-OTP header as well.

    GitHub also supports OAuth2 tokens sent in headers, or as URL parameters, which shouldn't require any special steps and are recommended if you're using 2FA.

    The reason you're getting "Not found" instead of something like "Please authenticate" is that

    Requests that require authentication will return 404 Not Found, instead of 403 Forbidden, in some places. This is to prevent the accidental leakage of private repositories to unauthorized users.