PHP example needed - Report Exporter

InnovAsian
InnovAsian Expensify Customer Posts: 20 Expensify Newcomer

HELP - Report Exporter

I having tried many variations and cannot get past the "No Template Submitted" error.
I have figured out how to submit the requestJobDescription portion, but do not know how to add the report template. I created a template file, but how do I duplicate the "--data-urlencode" step in the code below?

=-----------------------------------------------------------------------------------=
// Global for Expensify
$url="https://integrations.expensify.com/Integration-Server/ExpensifyIntegrations";
$partnerUserID = "...";
$partnerUserSecret ="...";
$emailid = "...";

// template file
$template_report = "template_report_export.ftl";
$send_template = fopen($template_report, "r");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, "requestJobDescription={
\"type\":\"file\",
\"credentials\":{
\"partnerUserID\": \"$partnerUserID\",
\"partnerUserSecret\": \"$partnerUserSecret\"
},
\"onReceive\" : {
\"immediateResponse\" : \"returnRandomFileName\"
},

    \"inputSettings\":{
        \"type\":\"combinedReportData\",
        \"reportState\": \"APPROVED\",
        \"filters\":{
             \"approvedAfter\":\"2018-07-01\" },
        \"outputSettings\":{
             \"fileExtension\":\"csv\" }
    }
}

");

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_INFILE, $send_template);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($template_report));
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);

$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);

Answers