Zoom Virtual Agent admins can add and edit the Script widget. The Script widget allows the bot to build actions using Javascript so that you don't need to rely on the UI to build flows. You can look for IDs, names, details on the site, or in an API. The results can be set in variables that can be stated back to the user.
async function main() {
var input = var_get()["order_email"];
//var input="alpha.adam@example.com";
log.info(input);
//replace with your url
var baseurl = 'https://zoomineer-hues.myshopify.com/admin/api/2023-01/customers/';
var url = baseurl + "search.json?query=email:" + input
var config = {
url: url,
headers: {
'X-Shopify-Access-Token': 'replace this with your token'
}
};
const resp = await req.get(url, config);
// log.info(JSON.stringify(resp.data.customers[0]))
const customer = resp.data.customers[0];
var cust_info = {
"id": customer.id,
"first_name": customer.first_name,
"last_name": customer.last_name,
"email": customer.email,
"last_order_id": customer.last_order_id
}
const order_id = cust_info.last_order_id;
log.info(JSON.stringify(cust_info));
// lookup orders by cust id
const cust_id = cust_info.id;
url = baseurl + cust_id + "/orders.json";
const resp1 = await req.get(url, config);
const orders = resp1.data.orders;
const order_ids = orders.map(getOrders);
function getOrders(order) {
return order.id;
};
var_set("order1", order_ids[0]);
var_set("order2", order_ids[1]);
// log.info(JSON.stringify(order_ids[1]))
return order_id;
}