Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
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.
By kamogelo
#795845
Good Day,

am using service task to configure POST API using JSON.

I am successfully getting the respond when am doing the test and am on debug mode.

my problem is how do I show my respond results on my dynaforms. and how do I use response configuration with variables?

I am using process maker 3.2 enterprise license
Attachments
service task respond config.PNG
Service Task Response Config
service task respond config.PNG (82.09 KiB) Viewed 5201 times
User avatar
By amosbatto
#795896
Can you post a screen shot of the variable in the lower window of the debugger? If I know the structure of the variable, I can tell you how to get it into a variable which you can display in a Dynaform field.
By kamogelo
#795923
Hi,

Thanks for the reply. I was able to get it right.

My Response Configuration was as followed and is working fine.

Response Property: message->data[0]->secretKey

Am just struggling on displaying Array response on grid.

Thanks
Kamo
User avatar
By amosbatto
#795928
kamogelo wrote:Am just struggling on displaying Array response on grid.
If you want to display it in a grid, then you need to insert it in an array of arrays. For example, let's say that you have a grid associated with the variable "clientList" and the grid contains fields with the IDs: "name", "business", "secretKey"

Then you can use the following trigger to create the grid with one row:
Code: Select all
@=clientList = array(
    1 => array(
           "name" => "John Doe",
           "business" => "Widgets Inc.",
           "secretKey" => @=message->data[0]->secretKey
    )
); 
Or to set the value in an existing grid variable in the first row:
Code: Select all
if (count(@=clientList) > 0) {
   @=clientList[1]["secretKey"] = @=message->data[0]->secretKey;
} 
or to set it in all the rows in the grid:
Code: Select all
for ($i = 1; $i <= count(@=clientList); $i++) {
   @=clientList[$i]["secretKey"] = @=message->data[0]->secretKey;
} 
By kamogelo
#795965
Thank you very much. Is working fine.

Now I need to pass grid values to array of (products and umbrellaAccounts) for REST API json request.
Code: Select all
        "umbrellaAccounts": [
        "123311331"
      ],
      "products": [
        9563,
        9565    
      ]
How do i do that? Do i create a trigger as well, cause when I pass @@gridId am getting an error.

This is what i get on debug mode:
Code: Select all
Array ( 
  [1] => Array ( 
    [Products] => 9563 
    [Products_label] => 9563 
  ) 
  [2] => Array ( 
    [Products] => 9565 
    [Products_label] => 9565 
  )
)
Regards
Kamo
User avatar
By amosbatto
#795976
I don't understand the context. Are you inside a PM trigger and you want to call some external REST service that is not from ProcessMaker?

If that is the situation, then you could do something like this:
Code: Select all
$aData = array(
     "umbrellaAccounts" => array(
         "123311331"
      ),
      "products" => array()
);
foreach (@=gridVariable as $aRow) {
      $aData['products'][] = $aRow['Products'];
}

//then call your REST endpoint:
$url = 'http://someExternalRest.com/endpoint'; //change to the URL of your REST endpoint

$ch = curl_init($url); 
//if you have logged in, then you will have an $accessToken. If not, then this next line isn't necessary:
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer ". $accessToken)); 

curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($aData)); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

//execute REST call. If returning JSON, then use json_decode():
$oRet = json_decode(curl_exec($ch)); 
//get status code, which should be 200, 201 or 204 if executed correctly:
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
This page explains how to execute REST calls in PHP: http://wiki.processmaker.com/3.0/Callin ... T_Requests
By kamogelo
#795984
Thank you for your reply.

I will try this approach.

Am calling an external REST API.

See attached my request body using Service Task Settings. I was not using trigger before. but i will do now.

Thanks
Attachments
sadasdsad.PNG
sadasdsad.PNG (52.21 KiB) Viewed 5115 times

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]

Betvisa clone scripts are pre-built software solut[…]

A Bet365 Clone Script is essentially a ready-made […]