hub-api(1)

SYNOPSIS

hub api [-t] [-X METHOD] [--cache TTL] ENDPOINT [-F KEY-VALUE]

OPTIONS

-X, --method METHOD
    The HTTP method to use for the request (default: "GET"). The method is automatically set to "POST" if --field or --raw-field are used.

    Use -XGET to force serializing fields into the query string for the GET request instead of JSON body of the POST request.

-F, --field KEY-VALUE
    Send data in KEY=VALUE format. The VALUE part has some magic handling; see --raw-field for passing arbitrary strings.

    If VALUE starts with "@", the rest of the value is interpreted as a filename to read the value from. Use "@-" to read from standard input.

    If VALUE is "true", "false", "null", or looks like a number, an appropriate JSON type is used instead of a string.

    Unless -XGET was used, all fields are sent serialized as JSON within the request body. When ENDPOINT is "graphql", all fields other than "query" are grouped under "variables". See ⟨https://graphql.org/learn/queries/#variables⟩

-f, --raw-field KEY-VALUE
    Same as --field, except that it allows values starting with "@", literal strings "true", "false", and "null", as well as strings that look like numbers.

-H, --header KEY-VALUE
    An HTTP request header in KEY: VALUE format.

-i, --include
    Include HTTP response headers in the output.

-t, --flat
    Parse response JSON and output the data in a line-based key-value format suitable for use in shell scripts.

--cache TTL
    Cache successful responses to GET requests for TTL seconds.

    When using "graphql" as ENDPOINT, caching will apply to responses to POST requests as well. Just make sure to not use --cache for any GraphQL mutations.

ENDPOINT
    The GitHub API endpoint to send the HTTP request to (default: "/").

    To learn about available endpoints, see ⟨https://developer.github.com/v3/⟩. To make GraphQL queries, use "graphql" as ENDPOINT and pass -F query=QUERY.

    If the literal strings "{owner}" or "{repo}" appear in ENDPOINT or in the GraphQL "query" field, fill in those placeholders with values read from the git remote configuration of the current git repository.

EXAMPLES

    # fetch information about the currently authenticated user as JSON
    $ hub api user
    # list user repositories as line-based output
    $ hub api --flat users/octocat/repos
    # post a comment to issue #23 of the current repository
    $ hub api repos/{owner}/{repo}/issues/23/comments --raw-field "body=Nice job!"
    # perform a GraphQL query read from a file
    $ hub api graphql -F query=@path/to/myquery.graphql

SEE ALSO

hub(1)