I have tried using a custom action. The update invoice as currency, but no exchange rate.
Could you post the correct code or point me in the right direction using a custom event to do this.
Thanks,
I have tried using a custom action. The update invoice as currency, but no exchange rate.
Could you post the correct code or point me in the right direction using a custom event to do this.
Thanks,
Best answer by john mccauley
Thank you for your response.
I did manage to do this. QuickBooks has an exchange rate field. Needed to calculate the home amount correctly. I custom field would not work.
The issue was using the QuickBooks api correctly.
After battling with copilot that kept saying it could not be done. I fed it a link to the api. After that it did write the required code for a custom action.
// Define and export an async function to update an invoice in QuickBooks Online
export async function updateInvoiceWithExchangeRate({
invoiceId,
syncToken,
exchangeRate,
currencyCode,
currencyName,
customerId,
companyId
}: {
invoiceId: string;
syncToken: string;
exchangeRate: number;
currencyCode: string;
currencyName: string;
customerId: string;
companyId: string;
}): Promise<{ result: string }> {
// Construct the URL using the companyId
const url = `https://quickbooks.api.intuit.com/v3/company/${companyId}/invoice`;
// Prepare the request body with the necessary invoice details
const body = {
Id: invoiceId,
SyncToken: syncToken,
CurrencyRef: {
value: currencyCode,
name: currencyName // Include the currency name in the request body
},
ExchangeRate: exchangeRate,
CustomerRef: {
value: customerId
},
sparse: true
};
// Make a POST request to the QuickBooks API using fetchWithZapier
const response = await fetchWithZapier(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(body)
});
//return { Reponse: JSON.stringify(response) };
// Use throwErrorIfNotOk to handle any errors in the response
await response.throwErrorIfNotOk();
// Return a success message if the request was successful
return { result: 'Invoice updated successfully' };
}
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.