<?php
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'POST') {
$request = file_get_contents('php://input');
$json = json_decode($request);
$parameters = array();
$parameters = $json->result->parameters;
// Call SAP Cloud platform workflow API Fetch XSRF token
$username = <Enter Cloud username>;
$password = <Enter Password>;
$ch = curl_init('https://bpmworkflowruntimewfs-<username>trial.hanatrial.ondemand.com/workflow-service/rest/v1/xsrf-token');
$request_headers = array();
$request_headers[] = 'X-CSRF-Token: Fetch';
$request_headers[] = 'Content-Type: application/json';
$request_headers[] = 'Accept: application/json';
$request_headers[] = 'APIKey: <API Key>';
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($curl, $header) use (&$headers)
{
$len = strlen($header);
$header = explode(':', $header, 2);
if (count($header) < 2) { // ignore invalid headers
return $len;
}
$name = strtolower(trim($header[0]));
if (!array_key_exists($name, $headers)) {
$headers[$name] = [trim($header[1])];
} else {
$headers[$name][] = trim($header[1]);
}
return $len;
});
$tmpfname = dirname(__FILE__) . '/cookie.dat';
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
//Call workflow instance API, pass token and other data and trigger workflow
$resp = curl_exec($ch);
$context = array();
$context["context"]["material"] = $parameters->POMaterial;
$context["context"]["quantity"] = $parameters->POqty;
$context["context"]["description"] = $parameters->PODescription;
$context["definitionId"] = "mypurchaseorder";
curl_setopt($ch, CURLOPT_URL, 'https://bpmworkflowruntimewfs-<user name>trial.hanatrial.ondemand.com/workflow-service/rest/v1/workflow-instances');
$request_headers = array();
$request_headers[] = 'X-CSRF-Token: ' . $headers['x-csrf-token'][0];
$request_headers[] = 'Content-Type: application/json';
$request_headers[] = 'Accept: application/json';
$request_headers[] = 'APIKey: <key here>';
$request_headers[] = 'Content-Length: ' . strlen(json_encode($context));
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($curl, $header) use (&$headers)
{
$len = strlen($header);
$header = explode(':', $header, 2);
if (count($header) < 2) { // ignore invalid headers
return $len;
}
$name = strtolower(trim($header[0]));
if (!array_key_exists($name, $headers)) {
$headers[$name] = [trim($header[1])];
} else {
$headers[$name][] = trim($header[1]);
}
return $len;
});
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($context));
$resp = curl_exec($ch);
// Close request to clear up some resources
curl_close($ch);
$resp1 = json_decode($resp);
$response = new \stdclass();
$response->speech = '';
$response->displayText = 'PO sent for approval';
$response->source = 'webhook';
echo json_encode($response);
}
?>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |