Skip to content

api --preview docs are still very unhelpful #11239

Description

@jsoref

Describe the bug

"GitHub API preview names to request (without the "-preview" suffix)"

Means nothing to me.

I can't tell if this means that requests for certain apis will be sent without -preview. If that's the goal, then, the text should say "Send requests without -preview", but I don't think that's what's going on.

If it means "Include specific preview mime types in accepts request", then it should say something like that. My guess is that the goal is more like "GitHUB API preview names to include in request accept headers (names should omit -preview, but requests will include the suffix)."

Affected version

gh version 2.74.2 (2025-06-17)
https://github.com/cli/cli/releases/tag/v2.74.2

Steps to reproduce the behavior

  1. Run gh api --help|grep -A1 preview
  2. View the output:
    gh api --help|grep -A1 preview
      -p, --preview names         GitHub API preview names to request (without the "-preview" suffix)
      -f, --raw-field key=value   Add a string parameter in key=value format
    --
      # Opt into GitHub API previews
      $ gh api --preview baptiste,nebula ...
    

Expected vs actual behavior

A clear and concise explanation of what preview does

Activity

  1. babakks commented on Jul 7, 2025

    @babakks
    Member

    Thanks for opening this issue, @jsoref! 🙏

    I think I agree with you that the docs is not clear about the function of the --preview option. Seems like what it was before #3433 was kind of clearer.

    I can suggest an improvement like this:

    -p, --preview names         Opt into GitHub API previews (names are comma separated and should omit the `-preview` suffix)
    

    What do you think, @jsoref? Do you that's clear enough for users who are seeing it for the first time?

  2. added
    enhancementa request to improve CLI
    more-info-neededMore info needed from user/contributor
    gh-apirelating to the gh api command
    and removed
    bugSomething isn't working
    on Jul 7, 2025
  3. jsoref commented on Jul 7, 2025

    @jsoref
    ContributorAuthor

    That prose is definitely better.

    I'm not a fan of the omit I think "without" is easier to understand. Omit as a verb requires an actor and this is passive prose.

    That still only addresses half the problem. What is a preview? Is it really only a content type response?

  4. babakks commented on Jul 8, 2025

    @babakks
    Member

    I think defining a preview option as something related to a request's Content-Type header field, is both confusing and too much detail. I imagine, as a user, I'd want to see there's a way to opt into upcoming API features that are not yet part of the stable release. Perhaps, this can be explained like this in the --help docs of the command:

    $ gh api --help
    Makes an authenticated HTTP request to the GitHub API and prints the response.
    ...
    The command supports invoking preview-stage API endpoints/features, by providing
    the `--preview` option followed by the name of the preview features to enable.
    ...
    

    What do you think, @jsoref?

  5. jsoref commented on Jul 8, 2025

    @jsoref
    ContributorAuthor

    Maybe.

    Let's start with the easier part:

    -p, --preview names         Opt into GitHub API previews (names should exclude `-preview` and be comma separated)      
    
    $ gh api --help
    Makes an authenticated HTTP request to the GitHub API and prints the response.
    ...
    This command supports invoking preview-stage API endpoints/features, when
    using the `--preview` option with names of preview features to enable.
    ...
    

    That still leaves users the problem of discovering what previews are. Which seems incredibly challenging.

    I found:

    But I haven't been able to construct any query to actually find recent previews...

  6. babakks commented on Jul 11, 2025

    @babakks
    Member

    Regarding the discovery of preview features, I think you should consult with API schemas:

    • For the REST API, OpenAPI specs are available as explained in this doc. You can download the OpenAPI spec (based on the API/product version you're interested) and look for previews keys. As I checked for api.github.com, there's no ongoing preview at the moment (i.e. previews: []).
    • For the GraphQL API, you can find the link to download the schema in this doc. At the top of the schema, you can see the definition of a @preview directive like this:
      directive @preview(
        """
        The identifier of the API preview that toggles this field.
        """
        toggledBy: String!
      ) on ARGUMENT_DEFINITION | ENUM | ENUM_VALUE | FIELD_DEFINITION | INPUT_FIELD_DEFINITION | INPUT_OBJECT | INTERFACE | OBJECT | SCALAR | UNION
      Like REST APIs, I couldn't find anything decorated with this @preview directive. So, I guess there's no preview here either.

    As a disclaimer, I haven't tried discovering previews so far, so I maybe wrong.

  7. babakks commented on Jul 11, 2025

    @babakks
    Member

    I think we're ready to put down the A/C for this issue at this stage.

    Acceptance Criteria

    When I run gh api --help
    Then I see the --preview option is clearly documented like this:

    $ gh api --help
    Makes an authenticated HTTP request to the GitHub API and prints the response.
    ...
    This command supports invoking preview-stage API endpoints/features, when
    using the `--preview` option with names of preview features to enable.
    ...
    -p, --preview names         Opt into GitHub API previews (names should exclude '-preview' and be comma separated)      
    ...
    
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

    docsenhancementa request to improve CLIgh-apirelating to the gh api commandhelp wantedContributions welcome

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions