Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: amosbatto

Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#821915
I created a custom function:
Code: Select all
function executeCurl($request,$data,$token)
{
	$data_string = json_encode($data);
	@@data_string = $data_string;
	$ch = curl_init();
	curl_setopt_array($ch, array(
		CURLOPT_URL => $request,
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => "",
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 30,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => "POST",
		CURLOPT_POSTFIELDS => $data_string,
		CURLOPT_HTTPHEADER => array(
			"Authorization: Bearer " . $token,
			"cache-control: no-cache",
			"Content-Type: application/json",
			'Content-Length: ' . strlen($data_string)
		)
	));

	$result = curl_exec($ch);
	$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	@@statusCode = $statusCode;
	$err = curl_error($ch);
	curl_close($ch);
	if ($err) 
	{
		@@errorNo = "cURL Error #:" . $err . "<br>";
	} 
	else
	{
		if ($statusCode != 200 && $statusCode != 201) 
		{
			if (isset ($result) and isset($result->error))
			{
				@@error = "Error code: " . $result->error->code;
				@@errorMessage = $result->error->message;
			}
			else
			{
				@@error = "Error: HTTP status code: " . $statusCode;
			}
		}
		else
		{

			$arrayResponse = json_decode($result);
		}
	}
}
but when I try to call it with executeCurl($request,$data,$token) I just get a blank screen. Even if I remove the parameters, it doesn't work. The code works perfectly if I don,t put it in a function but I have so many similar calls that I would prefer to use a custom function because my code is way too long otherwise (500 lines and counting...)
Attachments
blank.PNG
blank.PNG (10.32 KiB) Viewed 1653 times
#827700
Thanks programerboy, but the problem is not the trigger, is the missing information on php functions in triggers.
I got my trigger working once I stopped using functions in triggers. I know that you can define custom function and load them before firing the trigger, I did read that somewhere on the forum, I just wish the wiki would provide more insight over the subject.
Cheers.

hi everybody , please help me to solve this proble[…]

There's no way to do that. The only way to do so i[…]

Hello, If you are using a version of ProcessMak[…]

I really appreciate the work you did. I got to kno[…]