HOME / COMMUNITY Switch to knowledge base

POST https://api.quickfile.co.uk/1.2/invoice/search` resulted in a `500 Internal Server Error

I am getting this error when attempting to access the API. The diagnostic on my script reproduces the exact JSON string that is passed to the API. When this is pasted into the sandbox, it works fine. I suspect there is something wrong with the way I am calling it.

I know I’m so close on this, any advice would be appreciated.

The operative lines of code are:

$guzzleClient = new GuzzleHttp\Client(["base_uri" => "https://api.quickfile.co.uk/1.2/"]);
.
.
try {
    $result = $guzzleClient->post("invoice/search", ["json" => jsonRequest($submissionNumber, $AccountNum, $md5Key, $ApplicationID)]);
    echo 'success';
}

etc

the function json request populates the template with the required parameters and returns a pure json string

{
  "payload": {
    "Header": {
      "MessageType": "Request",
      "SubmissionNumber": "as per parameter",
      "Authentication": {
        "AccNumber": "as per parameter",
        "MD5Value": "as per parameter1",
        "ApplicationID": "as per parameter"
      }
    },
    "Body": {
      "SearchParameters": {
        "ReturnCount": "100",
        "Offset": "0",
        "OrderResultsBy": "InvoiceNumber",
        "OrderDirection": "ASC",
        "InvoiceType": "RECURRING",
        "ShowDeleted": "false"
      }
    }
  }
}

Hi @Mike

I think this may be the issue. The URL is 1_2 rather than 1.2

Hopes were high, surely it could not be that easy. Unfortunately, same error from altered header

Marvin to Zaphod : Server error: POST https://api.quickfile.co.uk/1_2/invoice/search resulted in a 500 Internal Server Error response: {“Errors”:{“Error”:["Internal Error: XmlNodeConverter can only convert JSON that begins with an object. Path ‘’, line 1, (truncated…)

What exactly does jsonRequest return? From what I can tell looking at the guzzle documentation, the json => ... option expects to receive an object that it will serialize into JSON, not the pre-serialized JSON string.

If you want to post a JSON object you give it an associative array, so if you give it a string it is probably serializing that (wrapping it in double quotes and escaping embedded quotes as \")

1 Like

jsonRequest returns a string in exactly the same format as the sandbox template. I gather from what you are saying that it would be best to give it an associative array - and let guzzle convert it.

I’ll give that a go.

And it works - Perfect - Many thanks

Mike

2 Likes

This topic was automatically closed after 7 days. New replies are no longer allowed.