Skip to content
v2.7 (latest)

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 ​

  1. Create a ruleset named ProductPrices.

Create ​

  1. Create a constant named Product and set Constant type to External.
    ↳ Rulecube shows the External data settings section.

  2. In the URL field, enter the URL of the API you want to query. In this case: https://dummyjson.com/products/1

  3. In the Fetch frequency list, select Daily. And in the Time (GMT) field, enter 01:00 AM.
    ↳ Now, Rulecube re-fetches the value every night at one o'clock.

  4. Click HTTP settings.
    ↳ The HTTP settings section opens.

  5. In the Method list, select GET.

  6. 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"
      ]
    }
  7. 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:

json
Product.price

Which returns the value 549.

Likewise, you can refer to other elements:

Product.title
Product.stock

External 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: