Hi Kendash,
I thought it would be too confusing to post the code. Sorry about that. The php code related to the problem is below:
//The user and terminal details are stored in DB as well as Message Server settings
$GetSessionTokenSQL = "Select * from ConnectionData order by ID desc";
$GetSessionToken = mysqli_query($DBConnection, $GetSessionTokenSQL);
$SessionToken = mysqli_fetch_array($GetSessionToken);
$url = $SambaSettings["Address"] . ":" . $SambaSettings["Port"] . '/api/graphql';
$query = 'mutation loadTicket{loadTerminalTicket(terminalId:\"' . $TerminalID . '\", ticketId:\"' . $TicketID . '\"){id, uid, number}}';
//I can load the ticket without any problems.
$header = array();
$header[] = 'Authorization: bearer ' . $SessionToken["access_token"];
$header[] = 'dataType: json';
$header[] = 'Content-type: application/json';
$fields_string = '{ "query": "' . $query . '", "variables" : null , "operationName" : null }';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
echo "load result: " . $result . “
”;
//close connection
curl_close($ch);
$TicketList = json_decode(trim($result), TRUE);
for ($fidx = 0; $fidx < sizeof($FreeProductsArray); $fidx++) {
//$FreeProductsArray is an array that stores the orderUIDs of the orderlines that we want execute the commands on
$query = ‘mutation cancel{executeAutomationCommandForTerminalTicket(orderUid:"’ . $FreeProductsArray[$fidx] . ‘", terminalId:"’ . $TerminalID . ‘", name:“İkram”, value:"") {id}}’;
echo “free : " . $query . “
”;
//This query here returns { “message”: “An error has occurred.”}
$fields_string = ‘{ “query”: "’ . $query . '”, “variables” : null , “operationName” : null }’;
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
echo "Free result : " . $result . ‘
’;
$RequestResult = json_decode($result, TRUE);
}
$query = 'mutation CloseTicket{closeTerminalTicket(terminalId:\"' . $TerminalID . '\" )}';
echo "6 : " . $query . "<br>";
$fields_string = '{ "query": "' . $query . '", "variables" : null , "operationName" : null }';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
I hope this makes it more clear. Please let me know if any more clarification is required for the code.