在Zapier中连接GoCardLess与LexOffice时遭遇“仅支持绝对URL”错误的解决求助
在Zapier中连接GoCardLess与LexOffice时遭遇“仅支持绝对URL”错误的解决求助
我是个编程新手,现在在Zapier里写JavaScript代码对接GoCardLess和LexOffice,但遇到了棘手的问题——明明我配置的API URL都是以https://开头的绝对地址,却还是收到了“仅支持绝对URL”的错误提示,实在不知道问题出在哪,麻烦大家帮忙看看!
以下是我目前写的代码:
/** * Change this to false when a real invoice should be created (without "Entwurf Modus" in LexOffice) */ const isDraft = false; /** * API Tokens & URLs */ const goCardlessPaymentId = inputData["goCardLessPaymentId"] || inputData["Events Links Payment"]; const goCardlessAPIToken = inputData["goCardLessAPIToken"]; const goCardlessAPIUrl = inputData["goCardLessAPIUrl"]; const goCardlessPaymentStatus = inputData["goCardLessPaymentStatus"]; const lexOfficeAPIToken = inputData["lexOfficeAPIToken"]; const lexOfficeAPIUrl = inputData["lexOfficeAPIUrl"]; // Validate Payment ID if (!goCardlessPaymentId) { throw new Error("Error: Payment ID is missing or undefined."); } const paymentIds = goCardlessPaymentId.split(','); const invoiceDataForLexOfficeInvoices = []; const logs = []; for (const paymentId of paymentIds) { try { console.log(`🔍 Fetching GoCardless payment details for Payment ID: ${paymentId}`); const invoiceData = await getCustomerDataFromGoCardlessPaymentById( goCardlessAPIUrl, goCardlessAPIToken, paymentId, goCardlessPaymentStatus ); invoiceDataForLexOfficeInvoices.push(invoiceData); } catch (error) { console.error(`❌ Error processing payment ID ${paymentId}: ${error.message}`); logs.push({ error: error.message, paymentId }); } } for (const invoiceItem of invoiceDataForLexOfficeInvoices) { try { console.log(`📨 Sending invoice data to LexOffice:`, invoiceItem); const invoiceResponse = await createLexOfficeInvoice(lexOfficeAPIUrl, lexOfficeAPIToken, invoiceItem, isDraft); logs.push(invoiceResponse); } catch (error) { console.error(`❌ Error creating LexOffice invoice: ${error.message}`); logs.push({ error: error.message }); } } return { output: logs }; /** * Functions + Single API Calls to GoCardless & LexOffice */ function getBaseAPIHeaders() { return { 'Content-Type': 'application/json', 'Accept': 'application/json', }; } async function getCustomerDataFromGoCardlessPaymentById(url, token, paymentId, requiredGoCardlessPaymentStatus) { if (!paymentId) { throw new Error("Payment ID is missing or undefined."); } const goCardlessPaymentUrl = `${url}/payments/${paymentId}`; let goCardlessApiConfig = { method: 'GET', headers: { 'Authorization': `Bearer ${token}`, 'GoCardless-Version': '2015-07-06', ...getBaseAPIHeaders() } }; // Fetch Payment Details const response = await fetch(goCardlessPaymentUrl, goCardlessApiConfig); const jsonResponse = await response.json(); console.log(`🔍 GoCardless API Response for ${paymentId}:`, JSON.stringify(jsonResponse, null, 2)); if (!jsonResponse.payments) { throw new Error(`GoCardless API did not return a 'payments' object. Full response: ${JSON.stringify(jsonResponse)}`); } const payment = jsonResponse.payments; const paymentStatus = payment.status; if (!paymentStatus) { throw new Error(`GoCardless payment status is undefined for Payment ID: ${paymentId}`); } if (paymentStatus.toLowerCase() !== requiredGoCardlessPaymentStatus.toLowerCase()) { throw new Error(`GoCardless payment status is ${paymentStatus}, but expected ${requiredGoCardlessPaymentStatus}.`); } return { created_at: payment.created_at, charge_date: payment.charge_date, amount: payment.amount / 100, // Convert cents to full EUR customer_id: payment.links.customer }; } async function createLexOfficeInvoice(url, token, invoiceData, isDraft = false) { let finalizedString = isDraft ? "" : '[?finalize=true]'; // Finalize only if not draft const lexOfficeCreateInvoiceBaseUrl = url + finalizedString; let lexOfficeApiConfig = { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, ...getBaseAPIHeaders() } }; const netAmount = invoiceData.amount; const lexOfficePayload = { "archived": false, "voucherDate": new Date().toISOString(), "lineItems": [ { "type": "custom", "name": "CL Coaching Community GmbH", "quantity": 1, "unitName": "Einzel €", "unitPrice": { "currency": "EUR", "netAmount": netAmount, "grossAmount": netAmount, "taxRatePercentage": 19 }, }, ], "totalPrice": { "currency": "EUR" }, "taxConditions": { "taxType": "gross" }, "paymentConditions": { "paymentTermDuration": 7, "paymentTermLabel": "Bitte den oben genannten Betrag innerhalb der nächsten 7 Tage auf das untenstehende Konto überweisen.", }, "shippingConditions": { "shippingDate": new Date().toISOString(), "shippingType": "service" }, "title": "Rechnung", "introduction": "Wie vorab besprochen stelle ich dir folgende Leistungen in Rechnung:", "remark": "Vielen Dank für die gute Zusammenarbeit." }; lexOfficeApiConfig.body = JSON.stringify(lexOfficePayload); const response = await fetch(lexOfficeCreateInvoiceBaseUrl, lexOfficeApiConfig); return await response.json(); }
我已经反复确认过Zapier里配置的goCardlessAPIUrl和lexOfficeAPIUrl都是完整的绝对URL(比如https://api.gocardless.com这类),但还是收到了“only absolute urls are supported”的错误提示,实在摸不着头脑,希望有经验的朋友能帮我排查下问题所在,非常感谢大家的耐心!
备注:内容来源于stack exchange,提问作者Shurui
相关产品推荐
相关产品推荐

