2

I am trying to create an Issue in my own repo using Github API, but for some reason it keeps throwing me an error

Route::post('/issue/create/{repo}',function ($_repo){

    $client = new Client([
        // Base URI is used with relative requests
        'base_uri' => 'https://api.github.com',
        // You can set any number of default request options.
//        'timeout'  => 2.0,
    ]);
    $url = '/repos/rehan-dckap/'.$_repo.'/issues';
    // Set various headers on a request
    $response = $client->request('POST', $url, [
        'query' => [
            'title' => 'IssueCreation',
            'body' => 'ThPI',
            'assignee' => '',
            'milestone' => 1,
            'labels' => [],
            'assignees' => []
        ],
        'headers' => [
            'Authorization'     => 'Bearer TOKENTOKENTOKENTOKEN'
        ]
    ]);
    return  response($response->getBody());
});

ERROR

Client error: POST https://api.github.com/repos/rehan-dckap/qatouch-api-docs/issues?title=IssueCreation&body=ThPI&assignee=&milestone=1 resulted in a 422 Unprocessable Entity response: { "message": "Invalid request.\n\nFor 'links/0/schema', nil is not an object.", "documentation_url": "https://develo (truncated...)

Can someone guide me?

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Rehan
  • 3,813
  • 7
  • 37
  • 58

2 Answers2

0

I've taken quite a bit of time to try and understand what the problem is here, but without running the code itself it will be a bit tricky. Can you provide an online sandbox with that code so I can play with it? I'm happy to provide the token myself. There's two main things here.

First the 422 generally means that there was an error parsing the payload. Looking at your payload, and the error message I would try to start by removing all non-mandatory fields starting by the arrays. If we look at the error message it's saying Nil is a not an object. My best guesses would be problems with the arrays or the assignee string.

Overall my tip in these cases is to reduce the API call to the bare functional. minimum and try to isolate the problem. I would go as far as using the GitHub Example they've posted on the API page and even remove the assignee since it's been deprecated:

{
  "title": "Found a bug",
  "body": "I'm having a problem with this.",
  "milestone": 1,
  "labels": [
    "bug"
  ]
}

Hope this helps.

bitoiu
  • 6,893
  • 5
  • 38
  • 60
0

here you can check the error code: https://developer.github.com/v3/

Sending invalid fields will result in a 422 Unprocessable Entity response.

HTTP/1.1 422 Unprocessable Entity
Content-Length: 149

{
  "message": "Validation Failed",
  "errors": [
    {
      "resource": "Issue",
      "field": "title",
      "code": "missing_field"
    }
  ]
}
Iguannaweb
  • 11
  • 2