Web Service REST API

Post Reply
RPioneer
Newbie
Posts: 1
Joined: Wed Nov 27, 2019 7:42 pm

Web Service REST API

Post by RPioneer »

Good evening!

Trying to run the job using PHP and REST APIs.
If you run the task through Postman, everything works out.
And if you throw cURL into the terminal, then he also works it out.
Here are the screens with Postman.


But if you insert code with cURL in PHP, formed in Postman, then nothing happens.
Sample code.

Code: Select all

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://192.168.6.24:51088/api/v1/job",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => array('flowId' => '119','objectId' => '4','jobName' => 'Tettftdst','metadata' => '[{ "id": "spMF_1", "name": "id", "value": "Demon" },{ "id": "spMF_2", "name": "event", "value": "Aly" }]','filePath' => 'agreement_3066556-55218.pdf','file'=> new CURLFILE('/D:/XAMPP/htdocs/Test_php/agreement_3066556-55218.pdf')),
  CURLOPT_HTTPHEADER => array(
    "Authorization: Bearer e75e59240391326c94ef5274414aa00307e0dff7",
    "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryLXxoX58ScYq3mwdt",
    "Cookie: sid=s%3A846636f9619e03ae200fa51b05beb2c882a70119.ebj37CVRwXYnYyPM7LfFw7nM1C0zc1RtJbK5KJap6Yo"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
Attachments
Capture_62.jpg
Capture_62.jpg (79.18 KiB) Viewed 2850 times
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Web Service REST API

Post by jan_suhr »

It is easier to go a more "modern" route.

Let the upload PHP-page store the file on its webserver and in the same time you upload an XML to a Switch Webhook. This is read in the flow and in the next step you get an XML to a Switch HTTP Request that downloads the file to the flow. It is much more quicker since the RestAPI require you to encode the upload in Base64 which take time and resources on both ends.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
Post Reply