Cannot export report

Hi there, I cannot seem to export a report using python3. I believe I have followed all the correct steps.
- Note that and are fill ins.
- I have tried calling the template as another .ftl file and storing the template as a string in the same script (below).
- I am using the python requests module (is this possible?)
- Do I need python to perform the curl on a command line?
- I have used curl on the command line with the same template and it works fine
- How do you insert the template call using python requests module
- I have tried stringifying 'requestJobDescription={...}' --data-urlencode 'template@my_template.ftl' as is shown in your API doc
- I have tried using requests.post (which is the only one that should work) and requests.get (just for kicks)
** I get HTTP 404 whenever I run with post
** I get HTTP 400 whenever I run with get (b/c you can't use get)
Below is my simplified code (.py files cannot be attached). Any help getting this to work would be great.
import logging
import json
import requests
from urllib.parse import urlencode
EXPENSIFY_API_ENDPOINT = "https://integrations.expensify.com/Integration-Server/ExpensifyIntegration"
type = "file"
credentials = {
"partnerUserID": "",
"partnerUserSecret": ""
}
onReceive = {
"immediateResponse": ["returnRandomFileName"]
}
inputSettings = {
"type": "combinedReportData",
"filters": {
"reportIDList": "38179851"
}
}
outputSettings = {
"fileExtension": "csv"
}
template = """
<#if addHeader == true>
Employee,ID,Date,Merchant and Comment,Category,Department,Location,Currency,Amount<#lt>
</#if>
<#assign reportNumber = 1>
<#assign expenseNumber = 1>
<#list reports as report>
<#list report.transactionList as expense>
<#-- Report level -->
${report.submitter.fullName},<#t>
${report.reportID},<#t>
${report.created},<#t>
<#-- Expense level --> ${expense.merchant} - ${expense.comment},<#t> ${expense.category},<#t> ${expense.tag.ntag-1},<#t> ${expense.tag.ntag-2},<#t> ${expense.currency},<#t> ${expense.amount}<#lt> <#assign expenseNumber = expenseNumber + 1> </#list> <#assign reportNumber = reportNumber + 1>
</#list>"""
def create_request():
params = {
"requestJobDescription": json.dumps({
"type": type,
"credentials": credentials,
"onReceive": onReceive,
"inputSettings": inputSettings,
"outputSettings": outputSettings
}),
"template": urlencode({"template": template})
# Have also tried -- "template": template
}
return params
def send_request(params):
response = requests.post(EXPENSIFY_API_ENDPOINT, data=params)
return response
def main():
params = create_request()
resp = send_request(params=params)
print(resp.content)
main()
Answers
-
Hi slai,
The variable
EXPENSIFY_API_ENDPOINT
in your code is incorrect, the value should behttps://integrations.expensify.com/Integration-Server/ExpensifyIntegrations
(you're missing thes
at the end).Can you try with the updated endpoint URL please?
If you're still having issues, you can try hosting your code snippet on gist.github.com or pastebin.com, which will make it easier to keep the correct format.Cheers