External Constant ​
An External constant lets you fetch a value from any website or API in the world.
In addition to explaining how to create and use an external constant, here we also present the External constant data page that lists all the external data constants that you defined.
Procedure ​
- Create a ruleset named
ProductPrices.
Create ​
Create a constant named
Productand set Constant type toExternal.
↳ Rulecube shows the External data settings section.In the URL field, enter the URL of the API you want to query. In this case:
https://dummyjson.com/products/1In the Fetch frequency list, select
Daily. And in the Time (GMT) field, enter01:00 AM.
↳ Now, Rulecube re-fetches the value every night at one o'clock.Click HTTP settings.
↳ The HTTP settings section opens.In the Method list, select
GET.Click Fetch.
↳ Rulecube calls the API and shows the JSON response in the Data field:json{ "id": 1, "title": "iPhone 9", "description": "An apple mobile which is nothing like apple", "price": 549, "discountPercentage": 12.96, "rating": 4.69, "stock": 94, "brand": "Apple", "category": "smartphones", "thumbnail": "https://i.dummyjson.com/data/products/1/thumbnail.jpg", "images": [ "https://i.dummyjson.com/data/products/1/1.jpg", "https://i.dummyjson.com/data/products/1/2.jpg", "https://i.dummyjson.com/data/products/1/3.jpg", "https://i.dummyjson.com/data/products/1/4.jpg", "https://i.dummyjson.com/data/products/1/thumbnail.jpg" ] }Click Save.
Use ​
Since Product is the constant that contains the JSON response and price is one of its elements, you can refer to the price element like this:
Product.priceWhich returns the value 549.
Likewise, you can refer to other elements:
Product.title
Product.stockExternal constant data page ​
If you create an external constant, Rulecube adds it to the External constant data page for your reference. This page shows the external constants of all your rulesets, and you open this page by clicking External Data from the top menu. Its content looks something like this:
