Overview

Note

These APIs are not frozen and can change at any time without warning. See the API versions available for details if you need stability.

This describes the details of the requests and responses you can expect from the addons.mozilla.org API.

Requests

All requests should be made with the header:

Content-type: application/json

Responses

Status Codes

There are some common API responses that you can expect to receive at times.

GET /api/v4/...
Status Codes
  • 200 OK – Success.

  • 201 Created – Creation successful.

  • 202 Accepted – The request has been accepted for processing. This usually means one or more asyncronous tasks is being executed in the background so results aren’t immediately visible.

  • 204 No Content – Success (no content is returned).

  • 400 Bad Request – There was a problem with the parameters sent with this request.

  • 401 Unauthorized – Authentication is required or failed.

  • 403 Forbidden – You are not permitted to perform this action.

  • 404 Not Found – The requested resource could not be found.

  • 500 Internal Server Error – An unknown error occurred.

  • 503 Service Unavailable – The site is in maintenance mode at this current time and the operation can not be performed.

Bad Requests

When returning a HTTP 400 Bad Request response, the API will try to return some information about the error(s) in the body of the response, as a JSON object. The keys of that object indicate the field(s) that caused an error, and for each, a list of messages will be provided (often only one message will be present, but sometimes more). If the error is not attached to a specific field the key non_field_errors will be used instead.

Example:

{
    "username": ["This field is required."],
    "non_field_errors": ["Error not linked to a specific field."]
}

Unauthorized and Permission Denied

When returning HTTP 401 Unauthorized and HTTP 403 Permission Denied responses, the API will try to return some information about the error in the body of the response, as a JSON object. A detail property will contain a message explaining the error. In addition, in some cases, an optional code property will be present and will contain a constant corresponding to specific problems to help clients address the situation programmatically. The constants are as follows:

Value

Description

ERROR_INVALID_HEADER

The Authorization header is invalid.

ERROR_SIGNATURE_EXPIRED

The signature of the token indicates it has expired.

ERROR_DECODING_SIGNATURE

The token was impossible to decode and probably invalid.

Maintainance Mode

When returning HTTP 503 Service Unavailable responses the API may be in read-only mode. This means that for a short period of time we do not allow any write requests, this includes POST, PATCH, PUT and DELETE requests.

In case we are in read-only mode, the following behavior can be observed:

  • GET requests behave normally

  • POST, PUT, PATCH, and DELETE requests return 503 with a json response that contains a localized error message

The response when returning HTTP 503 Service Unavailable in case of read-only mode looks like this:

{
    "error": "Some features are temporarily disabled while we perform websi…"
}

In case we are not in read-only mode everything should be back working as normal. To check if the site is in read-only mode before submitting a response, the site status api can be called.

Translated Fields

Fields that can be translated by users (typically name, description) have a special behaviour. They are returned as an object, by default, with languages as keys and translations as values, and by default all languages are returned:

{
    "name": {
        "en-US": "Games",
        "fr": "Jeux",
        "kn": "ಆಟಗಳು"
    }
}

However, for performance, if you pass the lang parameter to a GET request, then only the most relevant translation (the specified language or the fallback, depending on whether a translation is available in the requested language) will be returned.

Default API behavior

In API version 3 or 4 the response, if the lang parameter is passed, is a single string.

{
    "name": "Games"
}

This behaviour also applies to POST, PATCH and PUT requests: you can either submit an object containing several translations, or just a string. If only a string is supplied, it will only be used to translate the field in the current language.

v5 API behavior

In the experimental v5 API the response, if the lang parameter is passed, is an object containing only that translation.

{
    "name": {
        "en-US": "Games"
    }
}

For POST, PATCH and PUT requests you submit an object containing translations for any languages needing to be updated/saved. Any language not in the object is not updated, but is not removed.

For example, if there were existing translations of:

"name": {"en-US": "Games", "fr": "Jeux","kn": "ಆಟಗಳು"}

and the following request was made:

{
    "name": {
        "en-US": "Fun"
    }
}

Then the resulting translations would be:

"name": {"en-US": "Fun", "fr": "Jeux","kn": "ಆಟಗಳು"}

To delete a translation, pass null as the value for that language. (Note: this behavior is currently buggy/broken - see https://github.com/mozilla/addons-server/issues/8816 for more details)

Cross Origin

All APIs are available with Cross-Origin Resource Sharing unless otherwise specified.

Site Status

This special endpoint returns if the site is in read only mode, and if there is a site notice currently in effect. See maintainance mode for more details of when the site is read only and how requests are affected.

GET /api/v4/site/
Response JSON Object
  • read_only (boolean) – Whether the site in read-only mode.

  • notice (string|null) – A site-wide notice about any current known difficulties or restrictions. If this API is being consumed by a tool/frontend it should be displayed to the user.

API Versions

Default v4 API

All documentation here, unless otherwise specified, refers to the default v4 APIs, which are considered stable. The request and responses are NOT frozen though, and can change at any time, depending on the requirements of addons-frontend (the primary consumer).

Frozen v3 API

Any consumer of the APIs that requires more stablity may consider using the v3 API instead, which is frozen. No new API endpoints (so no new features) will be added to v3 and we aim to make no breaking changes. Despite the aim, we can’t guarantee 100% stability. The v3 API will be maintained for as long as Firefox ESR60 is supported by Mozilla, i.e. at least October 23rd 2019.

The documentation for v3 can be accessed at: External API (V3)

Experimental v5 API

The experimental v5 API contains some additional changes/features which are either unstable, in-progress, or currently unsupported by addons-frontend. It will eventually become the new default API when the current default, v4, is frozen and the stable v3 deprecated. Any reference to v5 specific behavior/properties/endpoints will be explicit in these docs.

v4 API changelog

v5 API changelog

These are v5 specific changes - v4 changes apply also.

  • 2018-09-27: created the v4dev API. The v4dev api is not available on AMO production server. See translations for details on the change to responses containing localisations. https://github.com/mozilla/addons-server/issues/9467

  • 2019-05-09: renamed the experimental v4dev api to v5 and made the v5 API generally available (on AMO production also)