Fetch custom fields values on Order

Hi,

We have orders that have a ‘trackingcode’ custom field and that is being populated correctly, but I’m unable to retrieve this tracking code custom field using the infusionsoft php sdk.

Example code that we’re using to fetch an order:
$order = $infusionsoft->orders()->find($id);
$order_attrs = $order->getAttributes();
… // Do something with $order_attrs below

I’m able to see custom fields when i call the following:
$order->model()

But it only lists the names of the custom fields and no values.

Any help would be great. Thanks.

Unfortunately we have not yet had a chance to implement full custom field support on the REST Orders placement endpoints, but it’s possible to retrieve them via the DataService in the XMLRPC API still. The selectedField value should be the API name of the Custom Field as shown in the Admin UI inside Infusionsoft.

Hi TomScott,

Thanks for the info. I’m still having trouble fetcing the custom fields. Which table should I be querying?

Per the XMLRPC table schemas, the Job table.

Thanks a lot, it worked!

Hey Tom, is it possible to do this via the PHP SDK provided? Some help will be much appreciated, as this whole XML-RPC thing is making my head spin! :laughing:

Hi Ankush,

Example is given here in the API Documentation:
https://developer.infusionsoft.com/docs/xml-rpc/#data-query-a-data-table

You would need to query the “Job” table.
https://developer.infusionsoft.com/docs/table-schema/#Job

Thanks, Pav! I’m actually running into Infusionsoft/TokenExpiredException though I have a valid token. This could be because I already have a cron job for refreshing InfusionSoft (Keap?) the access token, which then gets stored in the database (as there are several places where this access token gets used). So when building the SDK object, I’m skipping out on the refreshToken part and directly supplying a new one like this (Laravel code):

$this->sdk = new InfusionSoft([
            'clientId'     => env('INFS_CLIENT_ID'),
	        'clientSecret' => env('INFS_CLIENT_SECRET'),
	        'redirectUri'  => env('APP_URL'),
        ]);

        $token = new Token();
        $token->accessToken = $this->access_token;
        $this->sdk->setToken($token);

After this when I try to test with something like $sdk->data()->query('Contact', 1, 1, ['id' => 10], $returnFields, null, null); I get Infusionsoft/TokenExpiredException. I think the SDK can’t be “fooled” like this. :slight_smile: What would be the way to do this in my case?

Take a look at John’s video about OAuth.

I guess I didn’t explain myself correctly. Let me try again. :slight_smile: I actually already have an OAuth flow in place, but it’s being handled by a different process. My question is that in the docs, the PHP example in the docs goes like this:

$infusionsoft = new \Infusionsoft\Infusionsoft(array(
    'clientId' => CLIENT_ID,
    'clientSecret' => CLIENT_SECRET,
    'redirectUri' => REDIRECT_URL,
));

$infusionsoft->refreshAccessToken();

$infusionsoft->data()->query($table, $limit, $page, $queryData, $selectedFields, $orderBy, $ascending)

Is the $infusionsoft->refreshAccessToken(); part necessary? Because in my case, this will invalidate the access token other InfusionSoft jobs/processes have. Assuming I already have a valid access token, can it be used directly with the sdk without getting into the $infusionsoft->refreshAccessToken(); line?

If your other process is handling the Access Tokens, then you do not want to use any Refresh Access Token functions in your script.

I would say the example is a bit confusing.

Yes, which brings me to my original question: how do I pass to the SDK object the valid access token I already have?

You mentioned that you have another process handling the Access Tokens. Usually they would be stored in a database. So you could query that to get it back and use it.

Yes, but how do I pass the access token to the Infusionsoft object after it’s created with:

$infusionsoft = new \Infusionsoft\Infusionsoft(array(
    'clientId' => CLIENT_ID,
    'clientSecret' => CLIENT_SECRET,
    'redirectUri' => REDIRECT_URL,
));

There is a “setAccessToken” function you can use.

Thanks! I’m able to move past the token woes now. :slight_smile: Will open another discussion if I run into different problems. Thanks much, again!

Hi Tom,

Its been 2 years now, do we have a way to read custom fields from ORDERS rest api?

1 Like

Hi Tom,

Did you get any response for the above request? I am also looking to pull/read custom fields from orders rest API. Or Have you did any workaround to achieve it.?

2 years and half right now, don’t have enough development budget, Tom?