1

I want to update my variable by using gitlab APIs(using curl). But I am getting below error {"message":"401 Unauthorized"}

I have maintainer role. I have also created multiple times access token but nothing is working. Here below is scripts

NEW_VERSION="1234"

curl --request PUT --header "JOB-TOKEN: $CI_JOB_TOKEN" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/variables/TEST" --form "value=$NEW_VERSION"

curl --request PUT --header "PRIVATE-TOKEN:\ $token" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/variables/TEST --form "value=$NEW_VERSION"

curl --request PUT --header "PRIVATE-TOKEN: $token" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/variables/TEST" --form "value=$NEW_VERSION"

1 Answer 1

1

The error message {"message":"401 Unauthorized"} means that the API request is not authenticated. This can happen for a few reasons:

  • The access token is invalid. Make sure that you have created a valid access token with the api scope. GitLab documentation.
  • The access token is not for the correct project. Make sure that the access token is for the project that you are trying to update the variable in. GitLab documentation.
  • The access token is not for the correct user. Make sure that the access token is for the user that has permission to update the variable.

If you have confirmed that the access token is valid and for the correct project, you can try updating the variable again. Here is the correct curl command:

curl --request PUT --header "PRIVATE-TOKEN: $token" "{CI_API_V4_URL}/projects/${CI_PROJECT_ID}/variables/TEST" --form "value=$NEW_VERSION"

Replace $token with the value of your access token and $NEW_VERSION with the new value of the variable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.