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.

📘

JavaScript Storage API is available to Native apps with default user auth only.

Save data to storage

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.

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

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

📘

Saving data to storage

The data you wish to save to app storage must be stored in an object and values must be of "string" type at all times. The value size = 1mb max.

Get data from storage

To retrieve all data from storage, use EcwidApp.getAppStorage 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.

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

To retrieve data for a specific key, use EcwidApp.getAppStorage 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.

EcwidApp.getAppStorage('color', function(value){
  //prints 'red' 
  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.

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

📘

Please, note that application storage is erased during the application uninstallation.

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. See Get all storage data