Business Rules
The Business Rules API offers the ability to define different business behaviours for the shipping, payments and cart domains through a set of conditions.
When the merchant installs the app, the app must authenticate with Nuvemshop and create and individual Callback for the domain it supports and for the store that triggered the installation. These Callbacks represent the URL that we are going to consult when applying the rules to know what shipping options, payment options, etc. are applied at checkout.
In our platform, a Callback is created for a specific store.
Note: To create a Business Rules App you need to create an App in the Partners Portal and request our Partner Support Team (partners@nuvemshop.com.br or partners@tiendanube.com) to enable your app to access our APIs.
Installation flow
Below we have the definition of the API to integrate a new business rule provider. This API is what the partner will use in the installation flow to register with the corresponding configuration.
We can see that the URL is composed of the store_id and the domain to which the app corresponds and a token related to the installation of the app. Returns the No Content status on success.
Callback
| Field | Type | Description |
|---|---|---|
url | String | HTTPS URL where the data will be sent. |
event | String | Event the application will listen. See Events. |
domain | String | Domain in which the event occurs. See Domains. |
Domains
There are multiple domains supported on our platform. The app requires certain mandatory scopes in order to work with each domain, as follows:
payments: Requires the scopes:read_payment_options,read_payments.shipping: Requires the scopes:read_shipping.location: Requires the scopes:read_locationscart: No mandatory scopes required.
Events
The events supported on our platform are:
payments/before-filter: Event to filter payments options.shipping/before-filter: Event to filter shipping options.location/prioritization: Event for location prioritization.cart/before-finish: Event to block checkout completion.
Endpoint to create a Callback
Create a callback for a given store.
- URL:
/{*store_id*}/business_rules/integrations/{*domain*} - Method:
PUT
Request
Response
HTTP/1.1 204 No Content
Partner's API
In this section we explain that the partner's API must offer an endpoint with the following payload and response definitions. This endpoint represents the callbacks previously mentioned the partner must create.
Callback payload format definition
| Field | Type | Required | Description |
|---|---|---|---|
store_id | String | True | Store where the operation took place. |
cart_id | Number | if details.action is add | Id of the cart related to the operation. |
currency | String | True | ISO code of the currency of the cart. |
details | Details | True | Contains all the information related to the event. |
products | Products | True | Contains all the information related to products. |
customer | Customer | True | Contains all the information related to the customer. |
shipping | Shipping | if details.domain is shipping | Contains all the information related to the shipping. |
package | Package | if details.domain is shipping | Contains all the information related to the shipping package. |
locations | array<[Locations](location.md#properties)> | if details.domain is location | Contains all the information related to the locations. |
totals | Totals | if details.domain is payments, shipping, or cart | Contains all the information related to the amount to be charged to the consumer. |
Details
| Field | Type | Required | Description |
|---|---|---|---|
event | String | True | Represents the moment where the event must be triggered to perform the action. One of: shipping/before-filter, payments/before-filter, location/prioritization, cart/before-finish. |
action | String | True | Represents the action to perform. One of: filter. |
domain | String | True | Represents the domain in which the action take place. One of: cart, shipping, payments, locations. |
timestamp | Number | True | Update time. |
Products
| Field | Type | Required | Description |
|---|---|---|---|
id | Number | True | Id of the product line item. |
product_id | Number | True | Id of the product. |
quantity | Number | True | Number of products. |
stock | Number | True | Number of products left. |
variant_id | Number | True | Id of the product variant. |
price | String | True | Price of the product. |
categories | Array<[Categories](#categories)> | True | Product Categories. |
Categories
| Field | Type | Required | Description |
|---|---|---|---|
id | Number | True | Id of the category. |
parent | Number | False | Id of the parent Category. |
subcategories | Array<Number> | True | Ids of subcategories. |