James Murphy
asked on
Convert Curl Snippet from Postman to snippet I can use properly.
Hi,
Could someone please help me.
What i need to do, is convert the below to a proper snippet I can use in my php to do the curl post and post up different field values as required. I exported this from postman.
your help is very much appreciated!!
Could someone please help me.
What i need to do, is convert the below to a proper snippet I can use in my php to do the curl post and post up different field values as required. I exported this from postman.
your help is very much appreciated!!
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://someapi.com",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"template\"\r\n\r\nHi {{name}}! Click here {{url}} to pay your outstanding account.\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"C:\\xampp\\htdocs\\test.csv\"\r\nContent-Type: text/csv\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nTESTUPLOAD-1\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer XYZ",
"Cache-Control: no-cache",
"Postman-Token: 137a61fa-24dc-493e-9686-5e455d4d8a78",
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
That looks like it should work and it is PHP code... what exactly is the issue you're having?
ASKER
Hi,
Yes it does work, but i need to be able to feed variables including files into it, and everything I have tried seems to be incorrect.
Yes it does work, but i need to be able to feed variables including files into it, and everything I have tried seems to be incorrect.
ASKER
I was hoping to try and get it similar to the below:
rather than the current method.
any help is very much appreciated!
$ch = curl_init("http://www.example.com/");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
rather than the current method.
any help is very much appreciated!
ASKER
Basically I need to be able to feed a file number in there - when I attempt to post it is acting as though it cannot find the file required to be posted up.
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"template\"\r\n\r\nHi {{name}}! Click here {{url}} to pay your outstanding account ({{amount}}).\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"C:\\xampp\\htdocs\\test\\test.csv\"\r\nContent-Type: text/csv\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\n".$campaignname."-1\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
many thanks!