0

I'm trying to initiate a flow through the REST api using PHP:

$url = "https://myInstance.salesforce.com/services/data/v40.0/actions/custom/flow/EndCourse_and_Semester_Notification";

$headers = array(
    "Authorization: OAuth myAccessToken",
    "Content-type: application/json",
    "Content-Length: 0"
);

$body = '{}';

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
$response = curl_exec($curl);

var_dump($response;
curl_close($curl);

(myInstance replaces my instace and the same goes for the access token)

When i print the response i get the following error message:

string(118) "[{"message":"The HTTP entity body is required, but this request has no entity body.","errorCode":"JSON_PARSER_ERROR"}]"

Why is this happening? i have an empty body and a size defined. Also worth mentioning is that i tried doing the same without a body or size defined and then i got an error of:

"POST requires content-length"

1 Answer 1

3

flow expect input parameters while calling through API so you need to pass blank input array if you are not passing any value. Update your body with following json

{
"inputs": [
    {}
 ]
}

So your code will look like this

$url = "https://myInstance.salesforce.com/services/data/v40.0/actions/custom/flow/EndCourse_and_Semester_Notification";

$headers = array(
    "Authorization: OAuth myAccessToken",
    "Content-type: application/json",
    "Content-Length: 0"
);

$body = '{"inputs":[{}]}';

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
$response = curl_exec($curl);

var_dump($response;
curl_close($curl);

enter image description here

5
  • Tried $body = '{"inputs":[{}]}'; and i also tried: $uncoded_body = array("inputs" => array()); $body = json_encode($uncoded_body); both return the same error...
    – RealGigex
    Commented Sep 12, 2017 at 10:52
  • have you tested form workbench?
    – Himanshu
    Commented Sep 12, 2017 at 12:26
  • Tried through workbench right now, set the headers with the content length and the empty inputs array and still the same error.
    – RealGigex
    Commented Sep 12, 2017 at 12:50
  • @RealGigex match your input with updated answer screenshot or post your workbench screenshot with your question, this is working for me
    – Himanshu
    Commented Sep 12, 2017 at 14:51
  • YES! it works now! i had a pair of '' surrounding the body declaration in the workbench which caused the issue, and in my code i fixed it by using $body = "{\"inputs\":[{}]}"; instead of $body = '{"inputs":[{}]}'; Thank you!
    – RealGigex
    Commented Sep 12, 2017 at 15:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .