Fatal error from MessageFactory

You will find below a PHP Script that uses the raw XML to query the Orders for your specific field.
It is a single use script which uses cURL (Querying) and SimpleXMLElement (Results Parsing).

The “$app” and “$key” variables need to set your Application Name and Legacy API Encrypted Key.

The Amazon Order Number has been specified as a variable “$amazon_order_number”, which is set to a String Type.

It will just return the “Id” and “ContactId” fields in the result.

https://developer.keap.com/docs/xml-rpc/#data-query-a-data-table

<?php

    // Example PHP script to update the Contact Job Title field via the XML-RPC using the Legacy API Encrypted Key.

    ini_set("display_errors", 1);
    ini_set("display_startup_errors", 1);
    error_reporting(E_ALL);

    // API Connection.
    $app = "XXXXX";    // Your Keap Account Name.
    $key = "XXXXX";    // Your API Encrypted Key.

    // Amazon Order Number.
    $amazon_order_number = "123";

    // API Request.
    $request = "<?xml version='1.0' encoding='UTF-8'?>
<methodCall>
  <methodName>DataService.query</methodName>
  <params>
    <param>
      <value><string>{$key}</string></value>
    </param>
    <param>
      <value><string>Job</string></value>
    </param>
    <param>
      <value><int>100</int></value>
    </param>
    <param>
      <value><int>0</int></value>
    </param>
    <param>
      <value><struct>
        <member><name>_AmazonOrderNumber</name>
          <value><string>{$amazon_order_number}</string></value>
        </member>
      </struct></value>
    </param>
    <param>
      <value><array>
        <data>
          <value><string>Id</string></value>
          <value><string>ContactId</string></value>
        </data>
      </array></value>
    </param>
    <param>
      <value><string>Id</string></value>
    </param>
    <param>
      <value><boolean>0</boolean></value>
    </param>
  </params>
</methodCall>";

    $url       = "https://{$app}.infusionsoft.com:443/api/xmlrpc";
    $headers   = [ "Content-Type: text/xml", "Accept-Charset: UTF-8,ISO-8859-1,US-ASCII", "Expect:" ];
    $useragent = "XML-RPC Example";

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_ENCODING, "");
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_SSLVERSION, 0);

    $output = curl_exec($ch);

    curl_close($ch);

    // print_r($output);

    $xml = new SimpleXMLElement($output); 

    print_r($xml->params->param->value->array->data);

    // Loop through the Orders.
    foreach($xml->params->param->value->array->data->value as $order)
    {        
        // Loop through the Order Fields.
        foreach($order->struct->member as $field)
        {
            echo $field->name . ' - ' . $field->value->i4 . PHP_EOL;
        }
    }

The SDK would take away a lot of the API complexity here. Unfortunately due to the complexity of incorporating third party libraries they have created a house of cards for it.

Hope the script helps you out.