A query to find recurring invoices for a specified client is proving problematic - and just when everything else was proceeding so well. The query works in the sandbox, but when run from our application I get the following message.
Client error:
POST https://api.quickfile.co.uk/Invoice/Search
resulted in a400 Bad Request
response: {“Errors”:{“Error”:["19The element ‘SearchParameters’ in namespace ‘https://api.quickfile.co.uk’ has invalid child eleme (truncated…)
By way of diagnosis I put a breakpoint in the code to display the json code on the screen which I could then cut and paste into the sandbox. Sure enough, the pasted code in the sandbox works.
Also for diagnostics, I used a known ClientID that would return a result
The code works from the application. I know that there is something really obvious that I have missed which is laughing at me - but I cannot see it at the moment. Any advice would be appreciated.
The code that creates the calling parameters is as follows:
function getRecurrringInvoice($credentials, $ClientID) {
$request['payload']['Header'] = [
'MessageType' => "Request",
'SubmissionNumber' => $credentials['SubmissionNumber']
];
$request['payload']['Header']['Authentication'] = [
'AccNumber' => $credentials['AccNumber'],
'MD5Value' => $credentials['MD5Value'],
'ApplicationID' => $credentials['ApplicationID']
];
$request['payload']['Body']['SearchParameters'] = [
'ReturnCount' => 200,
'Offset' => 0,
'OrderResultsBy' => 'InvoiceNumber',
'OrderDirection' => 'ASC',
'InvoiceType' => 'RECURRING',
'ShowDeleted' => false
];
The above code works fine in the application, but fails when I add this section below. However, when I paste the json code into the sandbox from the 'echo statement, the sandbox returns the expected result
$request['payload']['Body']['SearchParameters']['ClientDetails'] = [
// 'ClientID' => $ClientID
'ClientID' => known good account number for testing
];
echo json_encode($request, JSON_PRETTY_PRINT); DIE(); // only for debugging
return $request;
}