Search code examples
githubgithub-api

Getting weird HTTP Response 400 error from GitHub when trying to create an Issue


Im making a script which automatically creates an issue after a push is made but for some reason when I run my script the API gives me a 400 error. The thing is I used this same code in the past and it was working just fine so I'm not sure if there is something wrong with my code or this specific API action.

This is my code:

for ((i=0;i<${#arr_libraryNames[@]};++i))
do 
    httpResponse=$(\
                    curl \
                    -H "Authorization: token ${OAuthToken}"\
                    https://api.github.com/repos/tpazhaidam/${arr_libraryNames[i]}/issues\
                    -d "{\"title\":\"Library Requires Template Update\",\"body\":\"When possible please update libraries to the most recent template version.\",\"assignees\":[\"tpazhaidam\"],\"labels\":[\"template update\"]}"\
                    -H "Accept: $API_VER_ACCEPTS"\
                    -X POST\                
                    )

    if [ "$httpResponse" != "201" ]; then
        echo "Failed to create issue for ${arr_libraryNames[i]} on GitHub"
        echo "HTTP Response $httpResponse"
        exit 1
    else
        echo "OK"
    fi                  
done 

This is the HTTP Response I am getting

HTTP Response
<html>
  <head>
    <meta content="origin" name="referrer">
    <title>Bad request &middot; GitHub</title>
    <meta name="viewport" content="width=device-width">
    <style type="text/css" media="screen">
      body {
        background-color: #f6f8fa;
        color: rgba(0, 0, 0, 0.5);
        font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
        font-size: 14px;
        line-height: 1.5;
      }
      .c { margin: 50px auto; max-width: 600px; text-align: center; padding: 0 24px; }
      a { text-decoration: none; }
      a:hover { text-decoration: underline; }
      h1 { color: #24292e; line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; }
      p { margin: 20px 0 40px; }
      #s { margin-top: 35px; }
      #s a {
        color: #666666;
        font-weight: 200;
        font-size: 14px;
        margin: 0 10px;
      }
    </style>
  </head>
  <body>
    <div class="c">
      <h1>Whoa there!</h1>
      <p>You have sent an invalid request. <br><br>
        Please do not send this request again.
      </p>
      <div id="s">
        <a href="https://support.github.com">Contact Support</a> &mdash;
        <a href="https://githubstatus.com">GitHub Status</a> &mdash;
        <a href="https://twitter.com/githubstatus">@githubstatus</a>
      </div>
    </div>
  </body>
</html>

Solution

  • All I did was remove the POST at the end of the curl and now it works.