The Wix Stores Data Requests package allows you to expose your Wix store’s data to one or more consumer sites using HTTP requests. When a consumer site makes an HTTP request to the exposed endpoints on your store’s site, they can do the following:
This package contains the code for both setting up the endpoints on your Wix store’s site, and for sending HTTP requests from consumer sites to those endpoints.
Note: To make things easier, we divided the package setup and content into 2 sections, one relevant for your store site, and the other for consumer sites.
The following setup instructions and package content are relevant for the store site only. For instructions about consumer sites, see the Consumer Sites section below.
Add a Wix Store to your site.
In your config.json backend file, set the storeUrl
property to a string with your Wix store’s URL. For example, https://some-account.wixsite.com/store
.
Create a secret key for your store to share with consumer sites. You can use a GUID generator.
Open the Wix Secrets Manager and create a new secret called store-secret
. Store the secret key from step 3 above in this secret.
Send the secret key you generated for your store to the owners of the consumer sites authorized to access your endpoints. Warning: Be careful to send your secret key securely! Exposing it is a serious security risk.
If you don’t already have one, create a new backend file called http-functions.js. Copy the code below and paste it into the file.
The following backend files are included in the package for use on your store site. Note that only exported functions that you can use in your site are listed here.
The code in this file contains configurations needed to use this package. Follow the instructions in step 2 of the Setup section to edit the file with your configurations.
The code in this file contains unexposed functions that get a list of your store’s products, get your store’s business information, and update a specific product’s data.
The code in this file contains functions that receive and process incoming HTTP requests from consumer sites to your store’s endpoints. To use the functions below in your code and receive HTTP requests, follow the instructions in step 6 of the Setup section.
get_products()
Implements a GET
HTTP endpoint that returns a list of store products.
Syntax:
Parameter:
request
: A WixHttpFunctionRequest object.Returns:
A WixHttpFunctionResponse object. If the request is successful, the object’s body
property contains a list of store products.
get_storeInfo()
Implements a GET
HTTP endpoint that returns your store’s business information.
Syntax:
Parameter:
request
: A WixHttpFunctionRequest object.Returns:
A WixHttpFunctionResponse object. If the request is successful, the object’s body
property contains an object with your store’s business information.
For example:
put_updateProduct()
Implements a PUT
HTTP endpoint that updates a specific product’s data. Requests to this function are authenticated with HMAC using the crypto npm package.
Syntax:
Parameter:
request
: A WixHttpFunctionRequest object.Returns:
A WixHttpFunctionResponse object. If the request is successful, the object’s body
property contains the updated product object.
The code in this file contains unexposed global helper functions and constants that provide functionality for various files in the package.
The following setup instructions and package content are relevant for consumer sites only. For instructions about the store site, see the Store Site section above.
store-secret
. Store the secret key from step 1 above in this secret.The following backend files are included in the package for use on consumer sites. Note that only exported functions that you can use in your site are listed here.
This file contains functions that consumer sites can use to send HTTP requests to the store site’s endpoints. Supported requests include getting store data and updating a specific product’s data.
To use the functions below in your code, import them with the following syntax:
getStoreData()
Gets the store’s data.
Syntax:
Parameters:
storeUrl
: The store site’s URL string. For example, https://some-account.wixsite.com/store
.scope
: A string representing the type of data you want to retrieve. One of the following:
products
: A list of all store products.storeInfo
: The store’s business information.Returns:
A promise that resolves to either an array of store products or an object containing store information based on the given scope. `
updateProductData()
Securely updates a specific product’s data. Requests sent by this function are authenticated with HMAC using the crypto npm package.
Syntax:
Parameters:
storeUrl
: The site store’s URL string. For example, https://some-account.wixsite.com/store
.
product
: An object containing the product’s ID, and the information you want to update.
_id
: The ID of the product you want to update (required).productInfo
parameter of the updateProductFields()
API.Returns:
A promise that resolves to an object with the updated product data and a success message.
The code in this file contains unexposed global helper functions and constants that provide functionality for various files in the package.
1.0 Initial version.
Wix store, http-functions