Use API Endpoints via CLI

Use the jf api command to invoke any JFrog Platform HTTP API directly from the JFrog CLI using your configured server URL and credentials.

The CLI automatically uses the configured hostname and authentication from jf config, or you can override them with --url, --access-token, or --server-id.

Use jf api with all JFrog Platform APIs, including:

Benefits of JF API

jf api provides:

  • Unified access to all JFrog APIs from one CLI command
  • Reuse of existing CLI authentication and configuration
  • Easier scripting and automation
  • Direct GraphQL and REST API access
  • Faster experimentation without a separate curl authentication setup

Prerequisites

To use jf api, verify the following:

  • JFrog CLI installed, version 2.100.0 or later
  • At least one server configured with jf config add, or --url and credentials passed inline

Synopsis

jf api <endpoint-path>

Aliases: none

Arguments

The following table lists command arguments.

ArgumentRequiredDescription
<endpoint-path>YesAPI path on the JFrog Platform host. The configured platform base URL is prepended automatically

Options

The following table lists command options.

OptionDescription
--access-tokenJFrog access token
--client-cert-pathClient certificate in PEM format
--client-cert-key-pathPrivate key for client certificate
-d, --dataRequest body as a literal string
--inputRead request body from file or stdin (-)
-H, --headerAdd HTTP request header (repeatable)
-X, --methodHTTP method. Default: GET
--server-idTarget configured server
--timeoutRequest timeout in seconds. 0 means no timeout
--urlOverride JFrog Platform URL
--userUsername
--passwordPassword
--insecure-tlsSkip TLS certificate verification
--disable-token-refreshDisable automatic access token refresh
--ssh-key-pathSSH private key path
--ssh-passphraseSSH key passphrase
--verbosePrint full HTTP request and response to stderr

Examples

Access REST APIs

List Users

To list all users in Access:

Request:

jf api /access/api/v2/users

Response:

{
  "users": [
    {
      "username": "admin",
      "realm": "internal",
      "status": "enabled",
      "uri": "/access/api/v2/users/admin"
    }
  ]
}

Get a User by Name

To get details for a single user:

Request:

jf api /access/api/v2/users/admin

Response:

{
  "username": "admin",
  "email": "[email protected]",
  "admin": true,
  "effective_admin": true,
  "profile_updatable": true,
  "disable_ui_access": false,
  "internal_password_disabled": false,
  "last_logged_in": "2024-07-17T13:43:28.608Z",
  "password_expired": false,
  "password_last_modified": "2023-07-04T14:14:46.064Z",
  "realm": "internal",
  "groups": [
    "readers"
  ],
  "status": "enabled",
  "policy_viewer": true,
  "watch_manager": true,
  "reports_manager": true,
  "policy_manager": true,
  "resources_manager": true,
  "manage_webhook": false,
  "platform_auditor": false
}

Create a User

To create a user from a JSON file:

  1. Create a user.json file with the user definition:

    {
      "username": "newuser",
      "email": "[email protected]",
      "password": "UseASecurePassword123",
      "admin": false,
      "groups": ["readers"]
    }
  2. Run:

    jf api /access/api/v2/users \
      -X POST \
      --input ./user.json \
      -H "Content-Type: application/json"

To create a user with an inline JSON body:

jf api /access/api/v2/users \
  -X POST \
  -d '{"username":"newuser","email":"[email protected]","password":"UseASecurePassword123"}' \
  -H "Content-Type: application/json"
📘

Note

The --data and --input command options are mutually exclusive.

Replace a User

To replace an existing user with a new definition:

jf api /access/api/v2/users/newuser \
  -X PUT \
  --input ./user.json \
  -H "Content-Type: application/json"

Delete a User

To delete a user:

jf api -X DELETE /access/api/v2/users/tempuser

Artifactory APIs

List Repositories

To list all repositories in Artifactory:

jf api /artifactory/api/repositories

Create a Local Maven Repository

To create a local Maven repository:

jf api /artifactory/api/repositories/my-maven-local \
  -X PUT \
  --input ./repo-maven-local.json \
  -H "Content-Type: application/json"

Update Repository Configuration

To update an existing repository's configuration:

jf api /artifactory/api/repositories/libs-release \
  -X POST \
  --input ./repo-config.json \
  -H "Content-Type: application/json"

Delete a Repository

To delete a repository:

jf api /artifactory/api/repositories/old-repo -X DELETE

Set a Request Timeout

To set a request timeout in seconds:

jf api /artifactory/api/repositories --timeout 10

OneModel GraphQL

To run a GraphQL query through OneModel:

jf api /onemodel/api/v1/graphql \
  -X POST \
  --input ./graphql-query.json \
  -H "Content-Type: application/json"

Use a Specific Server

To target a non-default configured server:

jf api /access/api/v2/users --server-id=my-server

Common Errors

The following table lists common errors, causes, and resolutions.

ErrorCauseResolution
{"status":401,"message":"Token failed verification: parse"}The access token has expired or is malformedRe-run jf config add to update credentials, or generate a new token in the JFrog Platform UI
{"status":403,...}Authenticated but insufficient permissionsUse an administrator token, or request the required permissions from your JFrog Platform administrator
{"status":404,...}The repository or path does not existVerify the repository key and path, and create the repository first if needed
{"status":403,"message":"Function is not supported when running on the cloud"} on /api/plugins/reloadEndpoint not available on JFrog SaaSThis feature is self-managed only.

See Also

For more information, see: