Skip to content

JS API Documentation

Learn how to use the Wized JavaScript API. Our API allows you to build on top of core features — so that you can create additional functionality, that's not possible with Wized alone.

Getting started

To use the Wized JavaScript API, you need to make sure that Wized have been loaded and initialised on the page. Otherwise you might get an error message similar to "Wized is not defined" or "Wized. ... is not a function" in the console.

To ensure this Wized has been loaded, add an on load wrapper around your Wized JS API code. You can use this everywhere inside the <body>:

js
window.onload = async () => {
  // Your Wized JS Code
};

Work with Wized data

  1. Get specific data

Use this method to the value of some data in the data store:

js
window.onload = async () => {
  const value = await Wized.data.get('r.2.d[0].name'); // Returns the value of "r.2.d[0].name"
};
  1. Get all data

js
window.onload = async () => {
  const dataStore = await Wized.data.getAll(); // Returns a snapshot of the full data store
};
  1. Run code whenever data changes (listener)

js
window.onload = async () => {
  Wized.data.listen('v.myvalue', async () => {
    const newValue = await Wized.data.get('v.myvalue'); // Get new value
    console.log('Value of v.myvalue changed to: ', newValue); // Console log new value
  });
};
  1. Set a variable

js
window.onload = async () => {
  await Wized.data.setVariable('username', 'Maria'); // Set value of "v.username"
  const value = await Wized.data.get('v.username'); // Get updated value => "Maria"
  console.log('Value of v.username changed to: ', value); // Console log updated value
};
js
window.onload = async () => {
  await Wized.data.setCookie('accesstoken', '123ioj3khk324143124'); // Set value of "c.accesstoken"
  const value = await Wized.data.get('c.accesstoken'); // Get updated value => "123ioj3khk324143124"
  console.log('Value of c.accesstoken changed to: ', value); // Console log updated value
};

Work with requests

  1. Trigger a request

js
window.onload = async () => {
  await Wized.request.execute('Load todos'); // Trigger request
  const response = await Wized.data.get('r.3.d'); // Get request response
  console.log(response); // Console log received request data
};
  1. Run code after a request

js
window.onload = async () => {
  Wized.request.await('Load todos', (response) => {
    console.log(response); // Log request response
  });
};
  1. Run code after all initial, on page load requests

js
window.onload = async () => {
  Wized.request.awaitAllPageLoad(async () => {
    const dataStore = await Wized.data.getAll();
    console.log(dataStore); // Console log the datastore snapshot
  });
};