How to use your API data in your product advice
Whenever you show the user the product advice, in most cases you will only show product data based on product feed data. However, in some cases you might want to show additional (dynamic) data like customer specific prices for example.
With the "API request mapping" feature, you can now enrich your product advice data with data supplied by any API endpoint you want.
Example
Let's take the above use-case as an example. To do this, a few steps are required:
1. Make your customer ID available in Qonfi
When you already have data available on your website that you want to use in your flow, you can send this data to Qonfi by setting them in window.qonfiVariables in JavaScript. For example:
window.qonfiVariables = {
"customerId": "123abc",
"bearer_token": "xxxxxxxx"
};
Just for demonstrative purposes, we've also added a bearer token to make sure this user is actually allowed to see the customer specific prices.
More information on how to use existing data from your website in your flow.
2. Enable API request mapping in Qonfi
Go to Settings -> Feed -> Advanced mapping and click the "Enable API request mapping".
3. Add the API request to get the customer specific price for the product
Go to "Feed -> Mapping" and click the "Configure API requests" button in the top-right.
Next, click the "Add API request" button and configure the API request.
Request Type
You can choose a request type that matches your API (GET, POST JSON, POST FORM).
Request URL
As you can see, we've set up an url that is dynamically populated with the product id, quantity and customerId. Depending on the logic in your API, by sending along the quantity you can also for example give volume discounts to your users.
Request headers
We also configured the request header to send along the bearer token to have your API authenticate the current user and check if it's allowed to view the requested customer prices. This, of course is also completely dependant on how you handle authentication in your API.
Request body (only when using the POST request type)
When using the POST request type, you can use the "Request body" to send additional data.
Result variable name
There variable in which the response will be saved and can be used later when mapping the fields.
4. Use the API response price in your mapping
The final step is to map the retrieved API data to the products fields. For example, our example API call returns the following response:
{
"price": 599,
"sale_price": 499
}
You can easily map the retrieved API data by using the {api.FIELD} syntax in a calculated property field. If you named your "Result variable name" differently, for example "api_request", you can use it like so: {api_request.FIELD}.
You can also use the api response data in calculations, as you can see in the "Excl. VAT Price" mapping in the example above.
Recap
That's it! With the "API request mapping" feature you can use any data from you website and use these in API calls to enrich your product advice. You can use variables, feed properties and api properties together to create a entirely dynamic product advice tailored to your user.
Documentation