Hello!
I've created a script with the purpose of letting me know whether or not a customer exists based on an External id (could be: 123456789). When the ID is entered in the ID_field in Airtable the script should run and check in Billwerk if an ID matches. If so, give me a thumbs up in a Status field.
Here is the Script:
let apiKey = "XXXXXX";
let secret = "XXXXXXX"
let endpoint = "https://api.billwerk.com/v1/customers";
// Define the Airtable table
let table = base.getTable("tblovGgaXXXXX");
// Define the function to check if a customer exists in Billwerk
async function checkCustomerExists() {
// Get the input data from Airtable
let airtableData = await table.selectRecordsAsync();
let inputData = airtableData.records.map((record) => record.getCellValue("External Id"));
// Fetch the customer data from Billwerk
let requestOptions = {
headers: {
Authorization: `Bearer ${apiKey}`,
},
};
try {
let response = await fetch(endpoint, requestOptions);
let customerData = await response.json();
// Compare the customer data to the input data
for (let customer of customerData) {
if (inputData.includes(customer.externalId)) {
// Update the status field in Airtable to indicate a match
await table.updateRecordAsync(record.id, {
"Status": "Exists in Billwerk"
});
}
}
} catch (error) {
console.error(error);
}
}
// Call the function to check if a customer exists in Billwerk
checkCustomerExists();
When testing the script in Airtable, I get an 'Test ran successfully', but also a CONSOLE.ERROR: {name: "d"}.
Can someone help me over the finish line here?