Get & update order custom field using XML-RPC API

Hi,
I’ve created a custom order field and trying to get & update it using the XML-RPC API but with no luck so far.
I’m calling for example order no. 2 using
$orders = $infusionsoft->orders()->find(2);
and I get all the field except for my custom field. This is the response I’m typing.

Infusionsoft\Api\Rest\OrderService Object
(
    [full_url] => https://api.infusionsoft.com/crm/rest/v1/orders
    [return_key] => orders
    [client:protected] => Infusionsoft\Infusionsoft Object
        (
            [url:protected] => https://api.infusionsoft.com/crm/xmlrpc/v1
            [auth:protected] => https://signin.infusionsoft.com/app/oauth/authorize
            [baseUri:protected] => https://api.infusionsoft.com/crm
            [tokenUri:protected] => https://api.infusionsoft.com/token
            [clientId:protected] => 
            [clientSecret:protected] => 
            [redirectUri:protected] => 
            [apis:protected] => Array
                (
                )

            [debug:protected] => 
            [httpClient:protected] => 
            [httpLogAdapter:protected] => Infusionsoft\Http\ArrayLogger Object
                (
                    [logs:Infusionsoft\Http\ArrayLogger:private] => Array
                        (
                        )

                )

            [serializer:protected] => 
            [needsEmptyKey] => 1
            [token:protected] => Infusionsoft\Token Object
                (
                    [accessToken] => ****************
                    [refreshToken] => ****************
                    [endOfLife] => 1528189926
                    [extraInfo] => Array
                        (
                            [token_type] => bearer
                            [scope] => full|xs469.infusionsoft.com
                        )

                )

        )

    [where:protected] => Array
        (
        )

    [updateVerb:protected] => put
    [primaryKey:protected] => id
    [optionalProperities:protected] => Array
        (
        )

    [attributes:protected] => Array
        (
            [id] => 2
            [title] => Order
            [status] => UNPAID
            [recurring] => 
            [total] => 0
            [contact] => Array
                (
                    [id] => 4
                    [email] => John@smith.com
                    [first_name] => John
                    [last_name] => smith
                    [company_name] => 
                    [job_title] => 
                )

            [creation_date] => 2018-05-27T20:02:39.000Z
            [modification_date] => 2018-05-27T20:08:22.000Z
            [order_date] => 2018-05-27T04:00:00.000Z
            [lead_affiliate_id] => 0
            [sales_affiliate_id] => 0
            [total_paid] => 0
            [total_due] => 0
            [shipping_information] => Array
                (
                    [id] => 2
                    [first_name] => John
                    [middle_name] => 
                    [last_name] => Smith
                    [company] => 
                    [phone] => 
                    [street1] => 
                    [street2] => 
                    [city] => 
                    [state] => 
                    [zip] => 
                    [country] => 
                )

            [refund_total] => 0
            [order_items] => Array
                (
                )

        )

    [hidden:protected] => Array
        (
        )

    [visible:protected] => Array
        (
        )

    [appends:protected] => Array
        (
        )

    [casts:protected] => Array
        (
        )

)
-------------------------- Done --------------------------

Then I tried to update it using:
$orders2 = $infusionsoft->data()->update('Orders', 2, ['_orderstatuscode', 'Sales']);
and this is what I get:

Error Happend
fXmlRpc\Exception\FaultException: No method matching arguments: java.lang.String, java.lang.String, java.lang.String in /My Domain path/infusion/vendor/lstrojny/fxmlrpc/src/fXmlRpc/Exception/FaultException.php:32
Stack trace:
#0 /My Domain path/infusion/vendor/lstrojny/fxmlrpc/src/fXmlRpc/Parser/XmlReaderParser.php(373): fXmlRpc\Exception\FaultException::fault(Array)
#1 /My Domain path/infusion/vendor/lstrojny/fxmlrpc/src/fXmlRpc/Client.php(156): fXmlRpc\Parser\XmlReaderParser->parse('call('DataService.upd...', Array)
#3 /My Domain path/infusion/vendor/infusionsoft/php-sdk/src/Infusionsoft/Infusionsoft.php(456): Infusionsoft\Http\InfusionsoftSerializer->request('DataService.upd...', 'https://api.inf...', Array, Object(fXmlRpc\Client))
#4 /My Domain path/infusion/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/DataService.php(146): Infusionsoft\Infusionsoft->request('DataService.upd...', '_orderstatuscod...', 'Sales')
#5 /My Domain path/infusion/urls2.php(10): Infusionsoft\Api\DataService->updateCustomField('_orderstatuscod...', 'Sales')
#6 {main}

Next Infusionsoft\Http\HttpException: No method matching arguments: java.lang.String, java.lang.String, java.lang.String in /My Domain path/infusion/vendor/infusionsoft/php-sdk/src/Infusionsoft/Http/InfusionsoftSerializer.php:34
Stack trace:
#0 /My Domain path/infusion/vendor/infusionsoft/php-sdk/src/Infusionsoft/Infusionsoft.php(456): Infusionsoft\Http\InfusionsoftSerializer->request('DataService.upd...', 'https://api.inf...', Array, Object(fXmlRpc\Client))
#1 /My Domain path/infusion/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/DataService.php(146): Infusionsoft\Infusionsoft->request('DataService.upd...', '_orderstatuscod...', 'Sales')
#2 /My Domain path/infusion/urls2.php(10): Infusionsoft\Api\DataService->updateCustomField('_orderstatuscod...', 'Sales')
#3 {main}

Can you guys point me in the right direction!
Thank you

I’m not terribly familiar with the inner workings of the PHP SDK, but it appears that the update you tried doesn’t match the exception you shared.

To be specific, the update you tried looks like $infusionsoft->data()->update but I would have expected to see something like $infusionsoft->data()-> updateCustomField.

Would you check to see if maybe you had a typo or a copy/paste error?

Now, regarding the exceptions themselves: it appears that updateCustomField may have been called without the final argument as an array. The reason I suggest this is because of this one line:

#5 /My Domain path/infusion/urls2.php(10): Infusionsoft\Api\DataService->updateCustomField('_orderstatuscod...', 'Sales')

This makes me think that the call you made looked like:

$infusionsoft->data()-> updateCustomField('_orderstatuscode', 'Sales')

when I would expect it to be:

$infusionsoft->data()->updateCustomField($yourCustomFieldId, ['_orderstatuscode', 'Sales'])

Would you double check your call or try the above?

Hi,
I tried the code you mentioned but I still got the same error message! it’s really confusing, I’ve tried almost every solution you guys have on the bulletin.

A colleague suggests the following:

There is no Orders table[, it] should be Job.

$orders2 = $infusionsoft->data()->update('Job', 2, ['_orderstatuscode', 'Sales']);

Hi Mike,
I did change Orders to Job earlier and still got the same thing!

Hi @nasser_halabi, try making the following modification to your code. The third parameter should be a map, not an array.

$infusionsoft->data()->update('Job', 2, ['_OrderStatusCode' => 'Sales']);

Also go into the Infusionsoft UI under Admin > Settings > General > Custom Fields > Order and click on “View the field database names (for the API)” and verify that database name here matches the field name you’re trying to set in the code (with the addition of a leading underscore). These field names are case sensitive so make sure it matches exactly.