1

I have written a shell script to create a pull request with Github Enterprise API.

#!/bin/sh
CURRENT_BRANCH=$(git branch --show-current)
git stash save
git checkout master
git pull
UUID=$(uuidgen)
git checkout -b "${UUID}"
npm version patch
git add package.json
git commit -m "#; update version script test"
git push origin "${UUID}"
curl -u [MY_USER_NAME]:[MY_TOKEN] https://github.[MY_ORGANIZATION].com/api/v3/user
curl \
  -X POST \
  -H "Accept: application/vnd.github.v3+json" \
  https://github.[MY_ORGANIZATION].com/api/v3/repos/Modules/[MY_REPO]/pulls \
  -d "{'head':'${UUID}','base':'master'}"

The log is displayed as below. It fail to create the pull request with the error

"message": "Must authenticate to access this API."

However, there seems no issue with the authentication.

// omit some useless log here
remote:
To github.microstrategy.com:Modules/mstr-web-hierarchy.git
 * [new branch]      23CFA0E3-33D1-489E-9E55-D38F92BB1B99 -> 23CFA0E3-33D1-489E-9E55-D38F92BB1B99
{
  "login": "shizhang",
  "id": 1191,
  // some useless properties here
{
  "message": "Must authenticate to access this API.",
  "documentation_url": "https://docs.github.com/enterprise/3.0/rest"
}

1 Answer 1

1

Your second curl does not seem to include any authentication information.

Try adding the same -u [MY_USER_NAME]:[MY_TOKEN] as you used in the first curl.

In other words, the first curl success does not mean other curls would benefit from an authenticated session.


Problems parsing JSON

Try with a simpler JSON, just for testing.
And pay attention to quotes: '${UUID}' would not be expanded, and would remain exactly as '${UUID}'.
See "How to include environment variable in bash line CURL?"

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

3 Comments

It does not wrok. An error message is thrown: { "message": "Problems parsing JSON", "documentation_url": "docs.github.com/enterprise/3.0/rest/reference/…" }
@A.Chao I agree but the original issue in your question was: ""Must authenticate to access this API.". I have answered that question.
@A.Chao I have edited the answer to address your error message, with a suggestion regarding the '${UUID}' part of your JSON payload.

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.