Skip to content

bj api

Make an authenticated request to the Bitbucket or Jira API.

Synopsis

bj api [OPTIONS] PATH

Description

Make an authenticated request against the Bitbucket or Jira REST API and print the JSON response. Choose the backend with --backend; --field adds parameters (query string for GET, JSON body otherwise). For a nested JSON body, pass it with --input <file> (- reads stdin), as with gh api --input; --field values then go to the query string. A response that is not JSON, such as an image or a file, is written to stdout as raw bytes, like gh api does.

Arguments

Argument Description
PATH API path, e.g. /repositories/{ws}/{repo}. (required)

Options

Option Description
-b, --backend {bitbucket|jira} Which API to call. (default: bitbucket)
-X, --method <text> HTTP method. (default: GET)
-f, --field <text> key=value parameter (repeatable).
--input <text> JSON request body from a file ('-' for stdin). Fields then go to the query.
-q, --jq <text> Filter JSON with jq.

Examples

bj api /repositories/{workspace}/{repo_slug}/pullrequests
bj api --backend jira /myself
# Full REST paths from the Jira docs work too
bj api --backend jira /rest/api/3/project/PROJ
bj api --backend jira -X POST /issue/PROJ-42/comment -f body=hi
# Send a nested JSON body from a file or stdin
bj api --backend jira -X PUT /issue/PROJ-42 --input body.json
jq -c . body.json | bj api -b jira -X PUT /issue/PROJ-42 --input -
# Non-JSON responses are written as raw bytes
bj api -b jira /rest/api/3/attachment/content/10001 > file.png

See also