Query language

To fetch the data of an entity such as an article or a customer you can use methods such as Article.get or Customer.get. To retreive the entire entity, use true or the empty object as the query.

API Console
Article.get(123456, true)
JSON
{
  "jsonrpc": "2.0",
  "id":      1,
  "method":  "Article.get",
  "params":  [123456, true]
}
Response
{123456, "articleNumber": "art001", …}
API Console
Article.get(123456, {})
Response
{"uid": 123456, "articleNumber": "art001", …}

You can specify what part of the data you want by providing a query object with the value true for all the keys that you want to get, e.g.

API Console
Article.get(123456, {"name": true})
Response
{"name": {"en": "Pink shirt", "sv": "Rosa skjorta"}}

This works for subkeys as well.

API Console
Article.get(123456, {"name": {"en": true}})
Response
{"name": {"en": "Pink shirt"}}

In this way, you can get several values.

API Console
Article.get({"name": true, "articleNumber": true})
Response
{"name": {"en": "Pink shirt", "sv": "Rosa skjorta"}, "articleNumber": "shirt001"}

A shortcut to get a single property lets you specify a string rather than an object with key: true, like this

API Console
Article.get(123456, "name")

which is the same as

API Console
Article.get(123456, {"name": true})

If all the keys are on the same level in the object, you can specify an array of key names.

API Console
Article.get(123456, ["name", "articleNumber"])

This is equivalent to

API Console
Article.get(123456, {"name": true, "articleNumber": true})

In some cases, a value refers to a unique identifier in a different API class.

API Console
Article.get(123456, {"articlegroup": true})
Response
{"articlegroup": 12345}

It is then possible to fetch that other object, in this case the article group using the Articlegroup class. To achieve this, specify that part of the query in object form.

API Console
Article.get(123456, {"articlegroup": {"uid": true, "name": "en"}})
Response
{"articlegroup": {"uid": 12345, "name": {"en": "Clothing"}}}

To fetch the entire article group without specifying every property in it, use an empty object as the part of the query referring to the article group.

API Console
Article.get(123456, {"articlegroup": {}})

Response
{"articlegroup": {"uid": 12345, "name": …, …}}

If the article doesn't have an article group, {"articlegroup": null} is returned, even if there is a query specifying properties inside the article group in question.

If the query is malformed, for example if you try to query into a scalar value, then you will get an error back. The error will always carry a pointer to where in the query it occured.

API Console
Article.get(123456, {"articleNumber": "uid"})

Response
Invalid query. (9004)
    /articleNumber