Hi everyone,
I'm trying to script a button to gather info from airtable and send it to an API which will turn it into an invoice and send it off. I'm getting an Error that makes no sense.
The code:
const customerNameField = 'Name';
const customerEmailField = 'Email';
const detailsField = 'Details';
const priceField = 'Price';
const amountField = 'Amount';
// Replace these values with your developer email and API key
const developerEmail = 'yehuda@officeours.co.il';
const apiKey = 'APIKEY';
// Replace this with the EZcount API endpoint
const ezcountApiEndpoint = 'https://demo.ezcount.co.il/api/createDoc';
// Get the current record's field values
const customerName = record.getCellValue(customerNameField);
const customerEmail = record.getCellValue(customerEmailField);
const itemDetails = record.getCellValue(detailsField);
const itemPrice = record.getCellValue(priceField);
const itemAmount = record.getCellValue(amountField);
// Construct the cc_email array
const ccEmails = [customerEmail, customerEmail]; // Use the same email twice
// Construct the JSON object
const jsonData = {
developer_email: developerEmail,
api_key: apiKey,
type: 320,
customer_name: customerName,
customer_email: customerEmail,
cc_email: ccEmails,
forceItems: 1,
show_items_including_vat: 1,
item: [
{
details: itemDetails,
price: itemPrice,
amount: itemAmount,
vat_type: 'INC' // You might need to adjust this
}
],
discount_value: 5,
discount_type: 'PERCENTAGE',
vat: '18',
price_total: 248,
tax_deducation: 10,
pay_until: '07/06/2020',
comment: 'Promise to fix all of your network issues',
email_text: 'Thank you for purecash from our shop.',
dont_send_email: 0,
send_copy: 1,
print_type: 'PDF',
auto_balance: 1
};
// Make an HTTP POST request to EZcount API
const response = await fetch(ezcountApiEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(jsonData)
});
// Handle the response from the EZcount API
let responseMessage = '';
if (response.ok) {
responseMessage = await response.text();
output.markdown('Invoice created successfully:', responseMessage);
} else {
responseMessage = `Error creating invoice. Status: ${response.status}`;
output.markdown(responseMessage);
}
// Update a specific Airtable field with the response
await table.updateRecordAsync(record, {
'Response Field Name': Confirmation
});
ERROR
on line 1 at s on line 1 at Generator._invoke on line 1 at Generator.next on line 1 at t on line 1 at a on line 1 on line 1 on line 1
Can anyone help?