Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.
AgentsAutomationApi

API quickstart for agents

Authenticate, push, pull, and inspect artifacts in Harness Artifacts using environment variables, CLI tools, and the HTTP API.

Authentication

All operations, including the REST management API, client CLIs, and HTTP package endpoints, authenticate with a single Harness API key. Set it once as an environment variable and use it everywhere.

export HARNESS_API_KEY="<pat-or-service-account-token>"

Header for REST and HTTP API calls: x-api-key: $HARNESS_API_KEY

Password for CLI clients (Docker, Helm, npm, Maven, pip, Cargo): use $HARNESS_API_KEY as the password. For service account tokens the username is the literal string _token. For PATs the username is your Harness account email.

TOKEN TYPE

Use a Service Account Token in CI/CD pipelines and automation. Personal Access Tokens (PATs) are tied to a user identity and break when that user leaves. Go to Authentication for agents for token generation and rotation guidance.


Environment setup

Set these five variables before running any of the commands in this guide. Every code block below uses them.

export HARNESS_API_KEY="<pat-or-service-account-token>"
export HARNESS_ACCOUNT_ID="<your-account-id>"          # visible in your Harness URL: app.harness.io/ng/account/<ID>
export HARNESS_EMAIL="<your-harness-account-email>"    # username for PAT auth only; service accounts use "_token" as username
export HAR_REGISTRY="<registry-name>"                  # the registry you are targeting
export HARNESS_MANAGER_HOST="app.harness.io"           # replace with your cluster hostname if different

Verify connectivity:

curl -s -o /dev/null -w "%{http_code}" \
  -H "x-api-key: $HARNESS_API_KEY" \
  "https://pkg.harness.io/pkg/$HARNESS_ACCOUNT_ID/$HAR_REGISTRY/"

Expected: 200. Any other code means the token is wrong (401), the registry does not exist (404), or permissions are missing (403). See Error reference below.


Push and pull

Pick the format your agent works with. All commands use the environment variables set above.

Log in

Push

Pull

Check if an image exists (no download)

Log in

Push

Pull

Inspect chart metadata without downloading

Configure ~/.m2/settings.xml. Run this once per agent environment:

pom.xml blocks. Add both to the project pom.xml:

Push

Pull (resolve dependencies)

Configure npm. Run this once per agent environment:

Or write ~/.npmrc directly:

Push

Pull

Configure Twine. Write ~/.pypirc:

Push

Pull a specific version

--no-deps installs only the named package without resolving transitive dependencies against the Harness registry. Remove --no-deps if your Harness registry also hosts the package's dependencies, or if you want pip to resolve them from other configured sources.

Configure Cargo. Write or append to ~/.cargo/config.toml:

Set the token. Write or append to ~/.cargo/credentials.toml:

Push

Pull

The Generic registry accepts arbitrary files over HTTP. No CLI installation is required; use curl.

Push a file

Pull a file

Check if a file exists (HEAD request, no download)

Delete a file

Nested paths are supported. Replace $FILE_NAME with a path like config/prod/settings.json.


Inspect artifacts via the REST API

Use the management REST API to list registries, query artifact metadata, and check vulnerability status. All endpoints require the x-api-key header.

List registries in your account

List artifacts in a registry

Get version details for a specific artifact

Go to REST API reference for the full OpenAPI specification, including request and response schemas.


Error reference

HTTP code
Meaning
Common cause
Fix

200

OK

—

—

401 Unauthorized

Token missing or invalid

x-api-key header absent, token revoked, or token expired

Regenerate the token and update $HARNESS_API_KEY

403 Forbidden

Token valid but insufficient permissions

Service account lacks Artifact Registries: Pull or Push permission at the registry scope

Add the required permission to the service account role

404 Not Found

Resource does not exist

Registry name typo, artifact not yet pushed, or wrong account ID

Check $HAR_REGISTRY, $HARNESS_ACCOUNT_ID, and the artifact name

409 Conflict

Resource already exists

Pushing an artifact version that is already present

Use a new version tag, or delete the existing version first

413 Request Entity Too Large

Upload exceeds size limit

File exceeds 5 TiB (Generic registry limit)

Split the payload or contact Harness Support


What to do next

Last updated

Was this helpful?