Unprocessable Entity when creating a pull request using node vs curl response

Can someone please let me know why the response is difference when calling the create pull request API using node.js vs curl is different?

Response from node fetch api

{
  status: 422,
  statusText: 'Unprocessable Entity'
}

Response from CURL

CURL =>

{
  "message": "Validation Failed",
  "errors": [
    {
      "resource": "PullRequest",
      "code": "custom",
      "message": "A pull request already exists for owner:branchName"
    }
  ]
}

Can someone please let me know why the response is difference when calling the create pull request API using node.js vs curl is different?

:wave: Hi there, @johnsonsamuel !

One possible reason the responses are different despite making the same call to the GitHub API is because they are two different client libraries with their own implementation details. It’s likely that node-fetch omits certain fields while keeping others unless otherwise specified. It’s not something I can confidently speak on since it’s not something GitHub built nor currently maintains, though it may be worthwhile to ask the project maintainers about this in an issue.

Speaking to the GitHub API portion of this, that 422 Unprocessable Entity is one of our documented Client errors when invalid fields are sent.

Given that error message––"A pull request already exists for owner:branchName"––my guess is that this request attempted to create another pull request for the same base and head branch for an existing pull request. Here are some approaches that might help:

  • close the existing pull request
  • create a pull request specifying a different base or head

I hope this helps, though I’m sure others in the Support Community may have other approaches to share! :sparkles:

1 Like

Thank you so much @francisfuzz!