Unexpected End of File Reached

Hello
I have been attempting to connect to our Expensify account via the API. I have had some success and can successfully export reports using simple templates such as those provided in the examples. However when attempting to use a Template for a pre-existing export that we have on our Expensify UI I receive the error:
"Unexpected end of file reached: lineNumber: '1' colNumber: '2842'
As far as I can tell, this error refers to the end of an If Statement within the template. I should point out that the X_POST and d- parts of the query work with simple templates, it is only when I try to use the template below that I encounter this issue.
I've tried having a root around the internet but when searching this error I seem to get into the weeds a bit as it is not very specific. I was wondering if anyone here could provide some insight or suggest some actions. Here is what I have been using so far (I could not work out how to format my code for this post, so apologies for the layout):
X_POST: "https://integrations.expensify.com/Integration-Server/ExpensifyIntegrations" d-: requestJobDescription={"type":"file", "credentials":{"partnerUserID":"my_id","partnerUserSecret":"my_secret"}, "onReceive":{"immediateResponse":["returnRandomFileName"]}, "inputSettings":{"type":"combinedReportData","reportState":"APPROVED,OPEN", "filters":{"reportIDList":"53274956"}}, "outputSettings":{"fileExtension":"csv"}, "onFinish":[{"actionName":"markAsExported","label":"TEST99"}, {"actionName":"email","recipients":"my_email@my_comany.com", "message":"Report is ready."}]}
Template:
<#if addHeader> Email,<#t> Employee ID,<#t> Merchant,<#t> Expense Date,<#t> Original Amount,<#t> Original Tax Amount,<#t> Original Currency,<#t> Local Amount,<#t> Local Currency,<#t> Tax Amount,<#t> Tax Code,<#t> Category,<#t> Location,<#t> Purpose,<#t> Comment,<#t> Attendees,<#t> Transaction Ref,<#t> Approved Date,<#t> Final Approved Date,<#t> Final Approver,<#t> Submitter,<#t> Report Name,<#t> Report ID,<#t> Report URL,<#t> Receipt Image URL,<#t> Policy ID,<#t> Policy Name,<#t> TripID,<#t> Expense Transaction ID,<#t> Cash Advance,<#t> Cash Return,<#t> Reimbursable/Non-Reimbursable (Yes/No)<#lt> </#if> <#assign blank = ""> <#list reports as report> <#if report.approvers?last.delegate?has_content> <#assign submitter = report.approvers?last.delegate.email> <#else> <#assign submitter = report.accountEmail> </#if> <#assign tripID = ""> <#list report.transactionList as expense> <#if expense.receiptObject.details.reservationList[0].confirmations[0].value?has_content!""> <#assign tripID = expense.receiptObject.details.reservationList[0].confirmations[0].value> </#if> </#list> <#list report.transactionList as expense> <#assign origAmount = ""> <#if expense.modifiedCreated?has_content> <#assign created = expense.modifiedCreated?date("yyyy-MM-dd")> <#else> <#assign created = expense.created?date("yyyy-MM-dd")> </#if> <#if expense.modifiedMerchant?has_content> <#assign merchant = expense.modifiedMerchant> <#else> <#assign merchant = expense.merchant> </#if> <#if expense.convertedAmount?has_content> <#assign amount = expense.convertedAmount/100> <#elseif expense.modifiedAmount?has_content> <#assign amount = expense.modifiedAmount/100> <#else> <#assign amount = expense.amount/100> </#if> <#if expense.details.origAmt?has_content> <#assign origAmount = ((expense.details.origAmt?number)/100)*-1> <#assign origCurrency = expense.details.origCur> </#if> <#if origAmount == ""> <#assign origCurrency = expense.currency> <#if expense.modifiedAmount?has_content> <#assign origAmount = expense.modifiedAmount/100> <#else> <#assign origAmount = expense.amount/100> </#if> </#if> <#if expense.ntag3?has_content> <#assign purpose = expense.ntag3> <#else> <#assign purpose = report.submitterPayrollID?keep_after(";")> </#if> <#if expense.tag?has_content> <#assign location = expense.tagGlCode> <#else> <#assign location = ""> </#if> <#assign attendeeList = ""> <#list expense.attendees as attendee> <#assign attendeeList = attendeeList + attendee.email + " "> </#list> <#if (expense.categoryGlCode == "ADV1")> <#assign advance = "Yes"> <#else> <#assign advance = "No"> </#if> <#if (expense.categoryGlCode == "RTN1")> <#assign return = "Yes"> <#else> <#assign return = "No"> </#if> <#if expense.bank == "cdf"> <#assign reference = expense.details.MasterCardFinancialTransactionId> <#else> <#assign reference = expense.externalID> </#if> <#if expense.modifiedTaxAmount?has_content && expense.modifiedTaxAmount < expense.taxAmount> <#assign taxAmount = expense.modifiedTaxAmount> <#assign taxableAmount = (taxAmount * (100 / (expense.taxRate?number))) + taxAmount> <#assign nonTaxableAmount = amount - taxableAmount> <#assign netAmount = taxableAmount - taxAmount> <#assign localAmount = amount - taxAmount> <#assign nonTaxableTaxAmount = 0> <#-- First line entry, taxable amount --> <#-- Email -->${report.accountEmail},<#t> <#-- Employee ID -->${report.submitterUserID},<#t> <#-- Merchant -->${merchant},<#t> <#-- Expense Date -->${created?string("dd/MM/yyyy")},<#t> <#-- Original Amount -->${netAmount?string("0.00")},<#t> <#-- Original Tax Amount -->${taxAmount?string("0.00")},<#t> <#-- Original Currency -->${expense.currency},<#t> <#-- Local Amount -->${netAmount?string("0.00")},<#t> <#-- Local Currency -->${report.currency},<#t> <#-- Tax Amount -->${taxAmount?string("0.00")},<#t> <#-- Tax Code -->${expense.taxCode},<#t> <#-- Category -->${expense.category},<#t> <#-- Location -->${location},<#t> <#-- Purpose -->${purpose},<#t> <#-- Comment -->${expense.comment?replace("u2019", "'")},<#t> <#-- Attendees -->"${attendeeList?remove_ending(", ")?replace("\"", "")}",<#t> <#-- Transaction Ref -->${reference},<#t> <#-- Approved Date -->${report.approvers[0].date?date("yyyy-MM-dd")?string("dd/MM/yyyy")},<#t> <#-- Final Approved Date -->${report.approvers?last.date?date("yyyy-MM-dd")?string("dd/MM/yyyy")},<#t> <#-- Final Approver -->${report.approvers?last.email},<#t> <#-- Submitter -->${submitter},<#t> <#-- Report Name -->${report.reportName},<#t> <#-- Report ID -->${report.reportID},<#t> <#-- Report URL -->https://www.expensify.com/report?reportID=${report.reportID},<#t> <#-- Receipt Image URL -->${expense.receiptObject.url},<#t> <#-- Policy ID -->${report.policyID},<#t> <#-- Policy Name -->${report.policyName},<#t> <#-- TripID -->${tripID},<#t> <#-- Expense Transaction ID -->${expense.transactionID},<#t> <#-- Cash Advance -->${advance},<#t> <#-- Cash Return -->${return},<#t> <#-- Reimbursable/Non-Reimbursable (Yes/No) -->${expense.reimbursable?then("Yes", "No")}<#lt> <#-- Second line entry, non taxable amount --> <#-- Email -->${report.accountEmail},<#t> <#-- Employee ID -->${report.submitterUserID},<#t> <#-- Merchant -->${merchant},<#t> <#-- Expense Date -->${created?string("dd/MM/yyyy")},<#t> <#-- Original Amount -->${nonTaxableAmount?string("0.00")},<#t> <#-- Original Tax Amount -->${nonTaxableTaxAmount?string("0.00")},<#t> <#-- Original Currency -->${expense.currency},<#t> <#-- Local Amount -->${nonTaxableAmount?string("0.00")},<#t> <#-- Local Currency -->${report.currency},<#t> <#-- Tax Amount -->${nonTaxableTaxAmount?string("0.00")},<#t> <#-- Tax Code -->IO0000,<#t> <#-- Category -->${expense.category},<#t> <#-- Location -->${location},<#t> <#-- Purpose -->${purpose},<#t> <#-- Comment -->${expense.comment?replace("u2019", "'")},<#t> <#-- Attendees -->"${attendeeList?remove_ending(", ")?replace("\"", "")}",<#t> <#-- Transaction Ref -->${reference},<#t> <#-- Approved Date -->${report.approvers[0].date?date("yyyy-MM-dd")?string("dd/MM/yyyy")},<#t> <#-- Final Approved Date -->${report.approvers?last.date?date("yyyy-MM-dd")?string("dd/MM/yyyy")},<#t> <#-- Final Approver -->${report.approvers?last.email},<#t> <#-- Submitter -->${submitter},<#t> <#-- Report Name -->${report.reportName},<#t> <#-- Report ID -->${report.reportID},<#t> <#-- Report URL -->https://www.expensify.com/report?reportID=${report.reportID},<#t> <#-- Receipt Image URL -->${expense.receiptObject.url},<#t> <#-- Policy ID -->${report.policyID},<#t> <#-- Policy Name -->${report.policyName},<#t> <#-- TripID -->${tripID},<#t> <#-- Expense Transaction ID -->${expense.transactionID},<#t> <#-- Cash Advance -->${advance},<#t> <#-- Cash Return -->${return},<#t> <#-- Reimbursable/Non-Reimbursable (Yes/No) -->${expense.reimbursable?then("Yes", "No")}<#lt> <#else> <#if expense.modifiedTaxAmount?has_content> <#assign taxAmount = expense.modifiedTaxAmount> <#elseif expense.taxAmount?has_content> <#assign taxAmount = expense.taxAmount> <#else> <#assign taxAmount = 0> </#if> <#assign originalNetAmount = origAmount - taxAmount> <#assign netAmount = amount - taxAmount> <#-- Email -->${report.accountEmail},<#t> <#-- Employee ID -->${report.submitterUserID},<#t> <#-- Merchant -->${merchant},<#t> <#-- Expense Date -->${created?string("dd/MM/yyyy")},<#t> <#-- Original Amount -->${originalNetAmount?string("0.00")},<#t> <#-- Original Tax Amount -->${taxAmount?string("0.00")},<#t> <#-- Original Currency -->${origCurrency},<#t> <#-- Local Amount -->${netAmount?string("0.00")},<#t> <#-- Local Currency -->${report.currency},<#t> <#-- Tax Amount -->${taxAmount?string("0.00")},<#t> <#-- Tax Code -->${expense.taxCode},<#t> <#-- Category -->${expense.category},<#t> <#-- Location -->${location},<#t> <#-- Purpose -->${purpose},<#t> <#-- Comment -->${expense.comment?replace("u2019", "'")},<#t> <#-- Attendees -->"${attendeeList?remove_ending(", ")?replace("\"", "")}",<#t> <#-- Transaction Ref -->${reference},<#t> <#-- Approved Date -->${report.approvers[0].date?date("yyyy-MM-dd")?string("dd/MM/yyyy")},<#t> <#-- Final Approved Date -->${report.approvers?last.date?date("yyyy-MM-dd")?string("dd/MM/yyyy")},<#t> <#-- Final Approver -->${report.approvers?last.email},<#t> <#-- Submitter -->${submitter},<#t> <#-- Report Name -->${report.reportName},<#t> <#-- Report ID -->${report.reportID},<#t> <#-- Report URL -->https://www.expensify.com/report?reportID=${report.reportID},<#t> <#-- Receipt Image URL -->${expense.receiptObject.url},<#t> <#-- Policy ID -->${report.policyID},<#t> <#-- Policy Name -->${report.policyName},<#t> <#-- TripID -->${tripID},<#t> <#-- Expense Transaction ID -->${expense.transactionID},<#t> <#-- Cash Advance -->${advance},<#t> <#-- Cash Return -->${return},<#t> <#-- Reimbursable/Non-Reimbursable (Yes/No) -->${expense.reimbursable?then("Yes", "No")}<#lt> </#if> </#list> </#list>
Many Thanks
Alex
Answers
-
Matt Moore Expensify Customer, Expensify Success Coach - Admin, Expensify Team Posts: 132 Expensify Team
Hey Alex_Dobbin,
The error message is related to the use of incorrect line endings (because it states "end of file on line 1"). Instead of passing:
<#list reports as report> <#list ...> ${expense.merchant} ....
Something like this is being passed:
<#list reports as report><#list ...>${expense.merchant}....
Can you make sure you're using CRLF line separators?
-
@Matt Moore Thanks for the information! I was passing the query as a single line to try and avoid issues with line seperators. Having rerun the query with indentation the error I receive is:
Could not process template ~~ editorMessage: 'Encountered "<", but was expecting one of:#012 <STRING_LITERAL>#012 <RAW_STRING>#012 "false"#012 "true"#012 <INTEGER>#012 <DECIMAL>#012 "."#012 "+"#012 "-"#012 "!"#012 "["#012 "("#012 "{"#012 <ID>' lineNumber: '133' colNumber: '87'
Should I make a new question for this specific error?
Alex
-
Ted Harris Expensify Success Coach - Admin, Expensify Team, Expensify Student Ambassador Posts: 359 Expensify Team
Hmmm @Alex_Dobbin - every time I see a
<
in your template, it looks correctly placed. From what I can seelineNumber: '133' colNumber: '87'
refers to(
from:<#-- Approved Date -->${report.approvers[0].date?date("yyyy-MM-dd")?string("dd/MM/yyyy")},<#t>
But that's obviously not a
<
so I'm not sure how to help from here actually.I fixed the formatting for your post by the way! For future reference, you can format this with the Paragraph options here: