Skip to main content

JSON API Connector

The JSON API connector lets you use a product feed from your own API with the Product Feed module. It is the right choice when your products are provided by an HTTP endpoint that returns JSON.

How It Works​

  1. Your API returns the products as a JSON array.
  2. LoyJoy calls the endpoint and maps the JSON fields to the product properties.
  3. The products appear in the chat via the Product Feed module.

Building the Endpoint​

It is recommended to host the endpoint on a hyperscaler such as Google Cloud or Amazon Web Services (AWS). For persistence, use a managed database such as Google Datastore or an equivalent service.

The following example is a Google Cloud Function that returns a static product feed. Replace the array with data from your database or shop system.

const functions = require('@google-cloud/functions-framework')

functions.http('productFeed', (req, res) => {
const products = [
{
title: 'Product 1',
description: 'Product 1 description',
price: '€10.99',
url: 'https://example.com/product-1',
tags: ['tag1', 'tag2']
},
{
title: 'Product 2',
description: 'Product 2 description',
price: '€20.99',
url: 'https://example.com/product-2',
tags: ['tag1', 'tag3']
}
]

res.setHeader('Content-type', 'application/json')
res.send(JSON.stringify(products))
})

Using It in LoyJoy​

  1. Deploy your endpoint and note the URL.
  2. Add the JSON API connector to your Product Feed module.
  3. Enter the URL and define the field mapping in the module.
  4. Publish and test with a preview chat.