// The Wallet Crew API configuration
var apiUrl = "https://app-qa.neostore.cloud/api/xxxxx/passes";
var apiKey = "xyz"; // API keys should be stored as secrets, not hardcoded.
// Fetch the list of customers from the workflow context (adapt to the instance data model)
var query = xtk.queryDef.create();
query.select("customerId") // Identifier field used to find passes
.from("customerTable"); // Source table
var customers = query.executeQuery();
for (var i = 0; i < customers.length; i++) {
var customerId = customers[i].customerId;
// Construct the API endpoint URL
var url = apiUrl + "?id.y2.customerId=" + encodeURIComponent(customerId);
// Define the payload for the API request
var payload = {
additionalData: {
adobe_message: "Exclusive offer: come visit us."
}
};
try {
// Execute the API call (adapt the HTTP client to the instance capabilities)
var response = http.request({
method: "PATCH",
url: url,
headers: {
"X-API-KEY": apiKey,
"Content-Type": "application/json",
"accept": "*/*"
},
body: JSON.stringify(payload)
});
logInfo("Customer ID " + customerId + ": update OK. Status: " + response.statusCode);
} catch (error) {
logError("Customer ID " + customerId + ": update failed. Error: " + error.message);
}
}