Canonical Snapcraft
Menu
  • Snap Store
  • About Snapcraft
  • Learn
    • Blog
    • Build
    • Docs
    • Tutorials
  • IoT
  • Forum
  • My account
    • My published snaps
    • My validation sets
    • My stores
    • Account details
    • Sign out
  • Sign in
Toggle side navigation
Toggle side navigation

Snap documentation

Use snaps

  • Snap tutorials
    • Get started
    • Install the daemon
      • AlmaLinux OS
      • Arch Linux
      • Debian
      • Elementary OS
      • Fedora
      • Linux Mint
      • Manjaro Linux
      • Raspberry Pi OS
      • openSUSE
      • Pop!_OS
      • Rocky Linux
      • Ubuntu
  • Snap how-to guides
    • Work with snaps
      • Manage updates
      • Connect interfaces
      • Configure snaps
      • Apps and aliases
    • Manage snaps
      • Create data snapshots
      • Use resource quotas
      • Disk space awareness
      • Set system options
      • Control services
      • Using components
      • Configure snaps with confdb
      • Manage validation sets
      • Snap deltas
      • Use the REST API
      • Use snapctl
    • Fix common issues
      • Test snapd fixes
      • Debug snaps
  • Snap reference
    • Operations
      • Glossary
      • System options
      • System architecture
      • Interfaces
        • Hardware interfaces
        • Media interfaces
        • Network interfaces
        • Security interfaces
        • System interfaces
        • Super-privileged interfaces
    • Administration
      • Network requirements
      • Distribution support
    • Development
      • Supported snap hooks
      • Services and daemons
      • Environment variables
      • REST API
        • snapd REST API
        • Error responses
      • YAML schemas
        • The snap format
        • The gadget snap
        • The kernel snap
    • Release notes
  • Snap explanation
    • How snaps work
      • Refresh awareness
      • Channels and tracks
      • Revisions
      • Transactional updates
      • Validation sets
      • Confdb configuration mechanism
      • Snap components
      • Snap performance
    • Interfaces
      • All about interfaces
      • Interface auto-connection
      • Interface hooks
    • Security
      • Security policies
      • Snap confinement
      • Classic confinement
      • Assertions
      • Snapd release process

Build snaps

Contribute to our docs

Using the REST API

The REST API provides access to snapd’s state and many of its key functions.

See below for details on accessing the API, authentication, JSON elements and error types, and see the API reference for which actions can be performed and which elements can be requested.

  • Accessing the API
  • Authentication
  • General response
    • synchronous responses
    • asynchronous responses

Accessing the API

The /run/snapd.socket UNIX socket is used to connect a client to the API.

:information_source: When experimenting the API on a Ubuntu Core system with a connected system user using a dangerous grade image, the curl snap must be installed with the devmode flag to access the UNIX socket.

To send a POST request with curl, for example, the following will ask snapd to install the hello snap from the edge channel:

sudo curl -sS --unix-socket /run/snapd.socket \
http://localhost/v2/snaps/hello \
-H "Content-Type: application/json" \
-X POST  -d '{"action": "install", "channel": "edge"}'

Similarly, the following curl command will remove a Quota group called allquotas:

sudo curl -sS --unix-socket /run/snapd.socket \
http://localhost/v2/quotas \
-H "Content-Type: application/json" \
-X POST -d '{"action": "remove", "group-name": "allquotas"}'

A request will return a JSON-formatted object. The following example uses curl to GET request the list of installed snaps, piped through jq for formatting:

$ sudo curl -sS --unix-socket /run/snapd.socket http://localhost/v2/apps \
| jq
{
  "type": "sync",
  "status-code": 200,
  "status": "OK",
  "result": [
    {
      "snap": "anbox-installer",
      "name": "anbox-installer"
    }
  ]
}

:information_source: HTTPS connections over a TCP socket are under consideration for a future release.

Authentication

The API incorporates three levels of access:

  • open: API requests will succeed without authorisation
  • authenticated: requires suitable authorisation to be provided with each request
  • root: root user gains authenticated access without sending authorisation

If an app or client is already running as root, it does not require the use of macaroons or any further authentication. The API will by default allow access to anything that needs to be authenticated.

Authorisation is provided by sending a Macaroon with the HTTP authorisation header. For example:

Authorization: Macaroon root="serialized-store-macaroon",discharge="discharge-for-macaroon-authentication"

If available, Polkit can also be used for authentication. The client may choose to allow user interaction for authentication, e.g. showing a graphical dialogue. This is done by setting an HTTP header (defaults to false):

X-Allow-Interaction: true

Responses

For each request, the following JSON object is returned:

Example:

{
    "type": "sync",
    "status-code": 200,
    "status": "OK",
    "maintenance": { 
        "kind": "system-restart", 
        "message": "system is restarting" 
    }
}

Fields

  • type: One of sync, async or error
  • status-code: HTTP status code matching the HTTP status line
  • status: HTTP reason phrase matching the HTTP status line
  • maintenance: JSON object containing maintenance information (optional)

Maintenance Fields

  • kind: Kind of maintenance restart, one of system-restart or daemon-restart
  • message: Text to show to user

Synchronous response

For a standard synchronous operation, the following JSON object is returned:

Example:

{
    "type": "sync",
    "status-code": 200,
    "status": "OK",
    "result": { "name": "value" },
}

Fields

In addition to the standard response fields, the following can also be present:

  • result: Result from the request. This can be any JSON structure and is commonly either an object or an array.

Asynchronous Response

When a request takes time to complete, an asynchronous response is returned.

The request is assigned a change id, which can be checked by requesting GET /v2/changes/[id].

Example:

{
    "type": "async",
    "status-code": 202,
    "status": "Accepted",
    "change": "401",
}

Fields

In addition to the standard response fields the following can be present:

  • change: identifier for the change in progress

Error response

If a request cannot be completed, an error response is returned.

Example:

{
    "type": "error",
    "status-code": 401,
    "status": "Unauthorized",
    "result": {
        "message": "access denied",
        "kind": "login-required",
    }
}

Fields

In addition to the standard response fields the following can be present:

  • result: Error information

Result Fields

  • message: Description of the error, suitable for displaying to a user
  • kind: Unique code for the error, to enable a snapd client to display appropriate behaviour (optional)
  • value: extra information on the error, typically a string for the snap name or an object with fields dependent on the kind (optional)

Last updated 5 months ago.

Help improve this document in the forum.

Back to top

© 2026 Canonical Ltd.

Ubuntu and Canonical are registered trademarks of Canonical Ltd.
Powered by Charmed Kubernetes

Join the forum, contribute to or report problems with, snapd, Snapcraft, or this site.

  • Terms of Service
  • Data privacy
  • Manage your tracker settings
  • Service status
  • Other functions
  • Share on Twitter
  • Share on Facebook
  • Share on YouTube