VtexMasterdata.js
Helpers to manipulate data from Vtex Masterdata
Table of contents
Main
dist/├── vtex-masterdata.js (UMD)├── vtex-masterdata.min.js (UMD, compressed)├── vtex-masterdata.common.js (CommonJS, default)└── vtex-masterdata.esm.js (ES Module)
Getting started
Direct download
Download the script here and include it.
You will need VtexUtils.js
Package Managers
VtexMasterdata.js supports npm under the name vtex-masterdata
.
npm install vtex-masterdata --save
Module Loaders
VtexMasterdata.js can also be loaded as an CommonJS or ES6 module (recomended).
// CommomJSvar VtexMasterdata = ; // ES6 module;
Usage
With UMD (Universal Module Definition), the package is available on VTEX
namespace.
// First, initialize VtexUtils.jsvar vtexUtils = ; // Initialize constructor passing VtexUtils.js as a paramvar vtexMasterdata = vtexUtils; // Set store name (https://store-name.vtexcommercestable.com.br)vtexMasterdata;
Methods
vtexMasterdata.newsletter(email[, newsletter[, entity]])
Newsletter opt-in / opt-out
-
email:
- Type:
String
- The email of the user to opt-in/out
- Type:
-
newsletter (optional):
- Type:
Boolean
- Default:
true
- Whether to opt-in/out
- Type:
-
entity (optional):
- Type:
String
- Default:
'CL'
- The Entity of the user
- Type:
Example
Remove user from newsletter
vtexMasterdata ;
vtexMasterdata.getUser(email, fields[, entity])
Get User by mail
-
email:
- Type:
String
- The email of the user
- Type:
-
fields
- Type:
Array
- A list of fields to retrieve
- Type:
-
entity (optional):
- Type:
String
- Default:
'CL'
- The Entity of the user
- Type:
Example
Get email, firstName and lastName by user e-mail (needs read properties set to public on Masterdata)
vtexMasterdata ;
vtexMasterdata.updateUser(email, data[, entity])
Update User by email
-
email:
- Type:
String
- The email of the user
- Type:
-
data:
- Type:
Object
- The data that will be updated.
- Type:
-
entity (optional):
- Type:
String
- Default:
'CL'
- The Entity of the user
- Type:
Example
Update user newsletter opt in, firstName and lastName (needs update properties set to public on Masterdata)
vtexMasterData ;
vtexMasterdata.insertUpdateUser(email[, data[, entity]])
Update a user if the email exists, or insert a new one if it doesn't
-
email:
- Type:
String
- The email of the user
- Type:
-
data (optional):
- Type:
Object
- The data that will be updated.
- Type:
-
entity (optional):
- Type:
String
- Default:
'CL'
- The Entity of the user
- Type:
Example
Create new user by email
vtexMasterdata ;
Update newsletter opt in user by email (needs update properties set to public on Masterdata)
vtexMasterdata ;
vtexMasterdata.insert(data[, entity])
Insert a document
-
data:
- Type:
Object
- The data that will be inserted
- Type:
-
entity (optional):
- Type:
String
- Default:
'CL'
- The entity of the document to insert
- Type:
vtexMasterdata.insertUpdate(id, data, entity)
vtexMasterdata.search(params, fields[, entity[, limit[, offset]]])
Performs a search
-
params
- Type:
Object
- The search parameters
- Type:
-
fields
- Type:
Array
- A list of fields to retrieve
- Type:
-
entity (optional):
- Type:
String
- Default:
'CL'
- The entity where the search will be performed
- Type:
-
limit (optional):
- Type:
Integer
- Default:
'49'
- The search limit
- Type:
-
offset (optional):
- Type:
Integer
- Default:
'0'
- The search offset
- Type:
Example
Search only stores with state = SP
vtexMasterdata ;
To search all results from entity, pass params as an empty object
vtexMasterdata ;
vtexMasterdata.fullSearch(params, fields, [filters[, entity[, limit[, offset]]]])
vtexMasterdata.get(id, fields, entity)
vtexMasterdata.exists(id, entity)
vtexMasterdata.uploadFile(id, entity, field, file)
License
VtexMasterdata.js is open-sourced software licensed under the MIT license.
Dependencies
jQuery 1.8.3+
VtexUtils.js
Todo
- Docs