LiteCart Public API

The official website and add-ons store have a public API currently offering read-only access to resources using REST. The response format is decided by the Accept header and JSON is the default.

Endpoint

https://www.litecart.net/api{/methodname}

Methods

The supported methods and their parameters are as following:

GET /releases?limit=10

Returns the releases. Apart from page and limit you can filter with:

Parameter Description
stable Only the stable releases
channel master for the stable releases, development for the unstable ones, distribution for the stable releases older than two weeks
since_version Only the releases newer than this version
date_from Only the releases created after this date
date_to Only the releases created before this date

GET /releases/{version}

A single release, including its release note.

GET /addons?query=my+search+string&limit=10

Returns the add-ons in the store. Apart from page and limit you can filter with:

Parameter Description
query Matches the name, the short description or the description of the add-on
category Matches the full name of the category, case-insensitive. A partial name does not match, so Admin finds nothing while Admin Apps finds the add-ons in that category.

When you give both, the add-on has to match both of them.

GET /addons/{id}

A single add-on. When the request carries an access token, the response also holds the license of that add-on for the store the token belongs to.

GET /addons/packages/{id}

Downloads a package of an add-on. This one needs an access token whose customer has access to the package, and it gives you the zip archive base64 encoded:

{
  "status": "ok",
  "content-type": "application/zip",
  "length": 1024,
  "etag": "b1946ac92492d2347c6235b4d2611184",
  "data": "UEsDBBQAAAA…"
}

GET /marketplace

The marketplace home, with the banners, the categories and the featured, best selling and most popular add-ons. GET /marketplace/home gives the same.

GET /marketplace/{section}

One section at a time. The section is one of categories, featured, best-selling or most-popular.

The banners are not available as a section of their own. They are only part of the marketplace home above, so GET /marketplace/banners answers with a HTTP 404.

Pagination

Paginated endpoints accept a page parameter and a limit parameter. The page size defaults to 25, and a limit that is not a positive number falls back to that default instead of raising an error.

GET /addons clamps the page size to a maximum of 100. GET /releases does not cap it, so ask for a sensible limit of your own if you are paging through releases.

Paginated endpoints return a Link header like the following:

Link: https://...?page=1; rel=first, https://...?page=2; rel=prev, https://...?page=3; rel=next, https://...?page=9; rel=last

The rel=prev and rel=next links are only present when there is a previous or a next page. On /addons the other query parameters, such as limit and query, are carried over into the links. On /releases only limit is.

You can extract a pagination link using regular expressions:

    if (preg_match('#<(.*?)>; rel="?next"?#m', $headers, $matches)) {
      $next_link = $matches[1];
    }

Response formats

The response format is decided by the Accept header. The default is JSON.

Accept Response
application/json JSON, pretty printed
application/xml XML. A nested value loses its parent keys, so the original of an image and the formatted of a price both end up as plain elements without telling you which object they came from.
text/csv CSV. One row per record, and the columns are the union of the records. A nested value is written as JSON in its cell, and an endpoint returning a single record is written as one row.
application/x-www-form-urlencoded Form encoded. The nested structure is kept in the keys, so an image becomes image[original]=….
application/yaml Not supported. The server has no YAML emitter, so the request fails with a HTTP 500 and an error message: {"error": "No YAML emitter available for this response"}.

Errors

An error is returned as a single error key holding the message:

{
  "error": "Invalid endpoint (nonsense)"
}

Always check for the error key and not only the HTTP status code. A request that fails without a status code of its own comes back as a HTTP 200 with an error body, so a client that only looks at the status code will read the error as a result.

A missing add-on answers with a HTTP 404 and the same error key, but a release version that does not exist answers with a HTTP 200 and an error body just like an invalid endpoint does. Check for the error key in both cases.

OpenAPI

A machine readable OpenAPI 3.0 specification of the API is served at GET /api, and the same URL serves a browsable API reference when the request accepts HTML.

The document lists the twenty endpoints of the API, the bin pack one included as /bin-pack. Asking for the document with Accept: application/yaml fails with the same YAML error as the other endpoints.

See Also

مضمون کی تفصیلات

23 جولائی 2022 کو litecart نے تخلیق کیا

ترمیمات

حال ہی میں ترمیم شدہ مضامین