Skip to content

Direct gh api call for PR review comments returned 422; review payload works #13358

Closed

Description

@xoelop

Update 2026-05-07

I found a working way to create inline PR review comments with gh api.

The working path is not gh pr review and not the direct POST /repos/{owner}/{repo}/pulls/{pull_number}/comments call I originally tried. It is to create a pull request review with a JSON payload and put the inline comments in the comments array:

cat > /tmp/review.json <<'JSON'
{
  "commit_id": "<HEAD_SHA>",
  "event": "COMMENT",
  "body": "## Code Review\n\nReview summary here.",
  "comments": [
    {
      "path": "path/to/file.py",
      "line": 42,
      "side": "RIGHT",
      "body": "Inline review comment body."
    }
  ]
}
JSON

gh api repos/OWNER/REPO/pulls/PULL_NUMBER/reviews \
  --method POST \
  --input /tmp/review.json

This creates a proper submitted PR review object with grouped inline comments on the relevant changed lines.

So my original conclusion was too broad: inline comments are possible with the CLI through gh api. The remaining gap is that gh pr review itself does not appear to expose a high-level way to pass path, line, side, or multiple inline comments, and the direct /pulls/{pull_number}/comments request shape from the REST docs still produced the 422 shown below in my tests.


Original report

The GitHub REST docs for "Create a review comment for a pull request" show a gh api example that should create an inline pull request review comment using start_line, start_side, line, and side:

https://docs.github.com/en/rest/pulls/comments?apiVersion=2026-03-10#create-a-review-comment-for-a-pull-request

However, when I ran that documented gh api shape against real pull requests and valid diff lines, GitHub returned a 422 internal validation error instead of creating the inline review comment.

This is related to the need discussed in #359, but this issue is narrower: the officially documented direct gh api/REST call appeared not to work as documented in my tests.

Reproduction

Environment:

gh version 2.83.2 (2025-12-10)
Authenticated token scopes include: repo, workflow

I tested this against open pull requests in a private repository. The PRs had normal changed files and the target lines were part of the PR diff.

Example diff from one PR:

@@ -97,9 +97,10 @@ jobs:
             Do not use GitHub inline review comments.
 
             For each finding:
-            - Start with a severity label: P0 for critical breakages, P1 for
-              high-impact bugs or security issues, P2 for moderate defects, and
-              P3 for low-risk improvements.
+            - Start with a colored priority marker and severity label:
+              🔴 P0 for critical breakages, 🟠 P1 for high-impact bugs or
+              security issues, 🟡 P2 for moderate defects, and P3 for low-risk
+              improvements.

Command, following the documented gh api example:

gh api \
  --method POST \
  -H 'Accept: application/vnd.github+json' \
  -H 'X-GitHub-Api-Version: 2026-03-10' \
  /repos/OWNER/REPO/pulls/104/comments \
  -f 'body=TEST inline REST range comment.' \
  -f 'commit_id=ce12021e0d53f7dae68aacc767e58360cdcc9fc8' \
  -f 'path=.github/workflows/claude-code-review.yml' \
  -F 'start_line=100' \
  -f 'start_side=RIGHT' \
  -F 'line=103' \
  -f 'side=RIGHT'

Actual response:

{
  "message": "Validation Failed",
  "errors": [
    {
      "resource": "PullRequestReviewComment",
      "code": "custom",
      "field": "pull_request_review_thread.base",
      "message": "An internal error occurred, please try again."
    }
  ],
  "documentation_url": "https://docs.github.com/rest/pulls/comments#create-a-review-comment-for-a-pull-request",
  "status": "422"
}

I also tested the same endpoint with a single line instead of a range:

gh api \
  --method POST \
  -H 'Accept: application/vnd.github+json' \
  -H 'X-GitHub-Api-Version: 2026-03-10' \
  /repos/OWNER/REPO/pulls/104/comments \
  -f 'body=TEST inline REST single-line comment.' \
  -f 'commit_id=ce12021e0d53f7dae68aacc767e58360cdcc9fc8' \
  -f 'path=.github/workflows/claude-code-review.yml' \
  -F 'line=100' \
  -f 'side=RIGHT'

It failed with the same 422 error.

I then tested the legacy position shape:

gh api \
  --method POST \
  -H 'Accept: application/vnd.github+json' \
  -H 'X-GitHub-Api-Version: 2026-03-10' \
  /repos/OWNER/REPO/pulls/104/comments \
  -f 'body=TEST inline REST position comment.' \
  -f 'commit_id=ce12021e0d53f7dae68aacc767e58360cdcc9fc8' \
  -f 'path=.github/workflows/claude-code-review.yml' \
  -F 'position=7'

It also failed with the same 422 error.

Expected behavior

The documented direct gh api call should create an inline pull request review comment on the requested diff line or range.

Actual behavior

The direct comments API returned 422 with an internal error on pull_request_review_thread.base, even when the line/range existed in the diff and the request shape matched the documented example.

Notes

A working CLI-based approach is shown at the top of this issue: create a review through POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews and include inline comments in the JSON payload's comments array.

Activity

  1. BagToad commented on May 6, 2026

    @BagToad
    Member

    @xoelop this is likely due to platform incident. Could you please try again once the incident is resolved?

    https://www.githubstatus.com/

  2. changed the title [-]Documented gh api call for creating PR review comments returns 422 internal error[/-] [+]Direct gh api call for PR review comments returned 422; review payload works[/+] on May 7, 2026
  3. BagToad commented on May 8, 2026

    @BagToad
    Member

    @xoelop I'm going to close this out because I'm assuming it was resolved with the resolution of the github incident, let me know if I misunderstood.

  4. xoelop commented on May 8, 2026

    @xoelop
    Author

    Thanks, this does look resolved now and consistent with the GitHub incident being the cause. I re-tested after the incident resolution and the approaches that previously failed now work.

    Tested successfully:

    1. Direct single-line inline PR comment via POST /repos/{owner}/{repo}/pulls/{pull_number}/comments using commit_id, path, line, and side.

    2. Direct multi-line range comment on the same endpoint using commit_id, path, start_line, start_side, line, and side.

    3. Legacy diff-position comment on the same endpoint using commit_id, path, and position.

    I also confirmed the review endpoint workaround still works for grouping inline comments in a submitted PR review via POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews with a comments array.

    So the 422 pull_request_review_thread.base errors I was seeing were most likely caused by the platform incident rather than the API payloads being invalid. I updated my comment in #359 with the working examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions