NAV

Storage in Ecwid API

Below you can find information about two different ways you can access your application storage depending on the type of an application you have.

Javascript Storage API

This JavaScript storage API allows to set and update values in the app storage right from your JavaScript code. You should use it if your app is client-side, works mainly in Javascript and you don’t plan to use a server.

Use the code examples below with the help of Ecwid JS SDK to manage user details in your application’s tab in Ecwid Control Panel.

Save data to storage

Save data to application storage

var data = { 
  color : 'red',
  size : 'big',
  page_id : '123456'
};

EcwidApp.setAppStorage(data, function(){
  console.log('Data saved!');
});

To save data to storage, create a Javascript object with all fields and values for them specified there. Once it’s ready, send it to app storage using EcwidApp.setAppStorage function to store them for future use.

This function supports object as an incoming data type only, so make sure that you send object as a first parameter of that function. The example code is available on the right.

Get data from storage

Get all data from application storage

EcwidApp.getAppStorage(function(allKeys) {
  // prints an array of key : value objects from app storage
  console.log(allKeys);
});

To retrieve all data from storage, use EcwidApp.setAppStorage with a callback function as a parameter. It will return an array of objects, containing all keys and their values in your app storage. You can save that response in a variable and access it in your app later.

Get data from application storage by key

EcwidApp.getAppStorage('color', function(value){
  //prints 'red' 
  console.log(value);
})

To retrieve data for a specific key, use EcwidApp.setAppStorage and specify the key as first parameter and callback function as the second one. It will return a value of the key you requested in a form of a string.

Get public app config

EcwidApp.getAppStorage('public', function(value){
  //prints '1234' 
  console.log(value);
})

Public application config is a part of application storage: data that you save there is kept in public key of the storage. In case if you need to check the value you saved to public app config, use EcwidApp.getAppStorage and specify the public key as first parameter and a callback function as a second one.

REST Storage API

This REST API allows to set, update and delete values in the application storage. You should usually use it if your code is executed on a server, i.e. you mainly use PHP, Ruby, Python, Java, and any other server-side programming language.

Get all storage data

Retrieves all stored data for the given store ID. Public application config can be found in the public key of your application storage.

Request

Request example

GET /api/v3/1003/storage?token=487487437834aasdfd HTTP/1.1
Host: app.ecwid.com
Content-Type: application/json;charset=utf-8
Cache-Control: no-cache

GET https://app.ecwid.com/api/v3/{storeId}/storage?token={token}

NameTypeDescription
storeIdnumberEcwid store ID
tokenstringoAuth token

Response

Response example (JSON)

[
  {
    "key":"birth_date",
    "value":"18.11.1987"
  },
  {
    "key":"sex",
    "value":"male"
  }
]

A JSON array of the objects in the following format

StorageElement

FieldTypeDescription
keystringThe key you set for the stored data
valuestringThe stored data

HTTP codes

HTTP StatusMeaning
403The access token doesn’t have the update_store_profile access scope
415Unsupported content-type: expected application/json or text/json
500Cannot retrieve the data because of an error on the server

Get storage data by key

Retrieves the stored data for the given store ID by the given key. Public application config can be found in the public key of your application storage.

Request

Request example

GET /api/v3/1003/storage/birth_date?token=487487437834aasdfd HTTP/1.1
Host: app.ecwid.com
Content-Type: application/json;charset=utf-8
Cache-Control: no-cache

Get public app config example

GET /api/v3/1003/storage/public?token=487487437834aasdfd HTTP/1.1
Host: app.ecwid.com
Content-Type: application/json;charset=utf-8
Cache-Control: no-cache

GET https://app.ecwid.com/api/v3/{storeId}/storage/{key}?token={token}

NameTypeDescription
storeIdnumberEcwid store ID
keystringKey (name) of the stored data
tokenstringoAuth token

Response

Response example (JSON)

{
  "key":"birth_date",
  "value":"18.11.1987"
}

A JSON object of the following format

StorageElement

FieldTypeDescription
keystringThe key you set for the stored data
valuestringThe stored data

Errors

Error response example

HTTP/1.1 404 Not Found
Content-Type application/json; charset=utf-8

{
    "error": "OTHER",
    "errorMessage": "Key not found"
}

In case of error, Ecwid responds with an error HTTP status code and JSON-formatted body containing error description

HTTP codes

HTTP StatusMeaning
403The access token doesn’t have the update_store_profile access scope
404The key is not found
415Unsupported content-type: expected application/json or text/json
500Cannot retrieve the data because of an error on the server

Error response body (optional)

FieldTypeDescription
errorstringType of the error
errorMessagestringError message

Add data to storage

Use this method to put a new data into the storage. If the key you specify in the request already exists, the corresponding value in the storage will be replaced with the submitted one. You can also create app public config data by using public as storage key in your request.

Request

Request example

POST /api/v3/1003/storage/my_key?token=487487437834aasdfd HTTP/1.1
Host: app.ecwid.com
Content-Type: application/json;charset=utf-8
Cache-Control: no-cache

Value of the new stored parameter

POST https://app.ecwid.com/api/v3/{storeId}/storage/{key}?token={token}

NameTypeDescription
storeIdnumberEcwid store ID
keystringKey (name) for the stored data (Limit: 1024 symbols)
tokenstringoAuth token

A key for the new key-value pair will be taken from the request URL. The data (value) is the request body (1MB max)

Response

Response example (JSON)

{
  "updateCount": 1
}

A JSON object with the status of operation

Status

FieldTypeDescription
successbooleantrue if the data has been added to the storage, false otherwise

HTTP codes

HTTP StatusMeaning
403The access token doesn’t have the update_store_profile access scope
415Unsupported content-type: expected application/json or text/json
500Cannot retrieve the data because of an error on the server

Edit storage data

Use this method to update data in the storage. If the key you specify in the request doesn’t yet exist, the corresponding value in the storage will be created. You can also update public application config by accessing public key in your request.

Request

Request example

PUT /api/v3/1003/storage/my_key?token=487487437834aasdfd HTTP/1.1
Host: app.ecwid.com
Content-Type: application/json;charset=utf-8
Cache-Control: no-cache

Updated value of the new stored parameter

PUT https://app.ecwid.com/api/v3/{storeId}/storage/{key}?token={token}

NameTypeDescription
storeIdnumberEcwid store ID
keystringKey (name) for the stored data (Limit: 1024 symbols)
tokenstringoAuth token

A key for the new key-value pair will be taken from the request URL. The data (value) is the request body (1MB max)

Response

Response example (JSON)

{
  "updateCount": 1
}

A JSON object with the status of operation

Status

FieldTypeDescription
successbooleantrue if the data has been changed in the storage, false otherwise

HTTP codes

HTTP StatusMeaning
403The access token doesn’t have the update_store_profile access scope
404The key is not found
415Unsupported content-type: expected application/json or text/json
500Cannot retrieve the data because of an error on the server

Delete storage data

Use this method to delete data in the storage by key.

Request

Request example

DELETE /api/v3/1003/storage/my_key?token=487487437834aasdfd HTTP/1.1
Host: app.ecwid.com
Content-Type: application/json;charset=utf-8
Cache-Control: no-cache

DELETE https://app.ecwid.com/api/v3/{storeId}/storage/{key}?token={token}

NameTypeDescription
storeIdnumberEcwid store ID
keystringKey (name) of the stored data
tokenstringoAuth token

Response

Response example (JSON)

{
  "deleteCount": 1
}

A JSON object with the status of operation

Status

FieldTypeDescription
successbooleantrue if the data has been removed from the storage, false otherwise.

HTTP codes

HTTP StatusMeaning
403The access token doesn’t have the update_store_profile access scope
404The key is not found
500Cannot retrieve the data because of an error on the server