PHP example needed - Report Exporter

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
$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={
\"partnerUserID\": \"$partnerUserID\",
\"partnerUserSecret\": \"$partnerUserSecret\"
\"onReceive\" : {
\"immediateResponse\" : \"returnRandomFileName\"

        \"reportState\": \"APPROVED\",
             \"approvedAfter\":\"2018-07-01\" },
             \"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);