Not getting custom key when retrieving data

Hello guys I have made some custom keys using your web view. Now I’m saving the data in which I have placed the custom keys with an underscore at the start but the problem is when I try to retrieve the data I don’t get the custom key. Can somebody tell me what is going wrong ?

I’m using rest api

So, to clarify, you are saving the data and that is working, right?

Are you appending ?optional_properties=custom_fields to your query for a contact when you try to retrieve the data?

yes the saving is working right

no no I’m not appending anything. I’m trying to retrieve the data like this

infusionsoftService->contacts()->get()

@JustinHandley I’m retrieving a list of contacts not one and I want to get the additional fields with it

anyone any help ??

Hi @Rohan_Jalil

So, you say you are using the Rest API, but I’m looking at your code and not figuring out what exactly you are doing. Are you using the php SDK? Or the Alternative php SDK? What is creating infusionsoftService - let me know and we should be able to get to the bottom of this.

@JustinHandley

yes I’m using php sdk provided by infusionsoft. infusionsoftservice is the object of this class Infusionsoft which infusionsoft sdk provides

Hmm. OK - sorry - I’ve been working in javascript for a while and haven’t looked at the PHP SDK in some time. From what I can tell, this should pass back custom fields as part of the object - they won’t have the custom field name (so if you are searching for that, you won’t find it) but will have the ID of the custom field. Are you sure that isn’t there?

If not, there are really only two options - on is trying to get someone at Infusionsoft to confirm the API is passing the information correctly, the other is to run debugging on the SDK itself, and unfortunately, I don’t have time to do that right now.

Do you not see the custom_fields node in the returned json at all?

@JustinHandley

and one more thing when I’m trying to retrieve a single contact it is returing me a empty custom_fields array where as If I see through the frontend I can see the data populated in it

$obj = $this->infusionsoftService->contacts()->where([
                    'id' => $singleData->id,
                    'optional_properties' => 'custom_fields,job_title'
                ]);

and this returns me this

[2017-08-28 13:45:32] local.DEBUG: Infusionsoft\Api\Rest\ContactService Object
(
    [full_url] => https://api.infusionsoft.com/crm/rest/v1/contacts
    [updateVerb:protected] => patch
    [return_key] => contacts
    [client:protected] => Infusionsoft\Infusionsoft Object
        (
            [url:protected] => https://api.infusionsoft.com/crm/xmlrpc/v1
            [auth:protected] => https://signin.infusionsoft.com/app/oauth/authorize
            [tokenUri:protected] => https://api.infusionsoft.com/token
            [clientId:protected] => xxxxxxxxxxx
            [clientSecret:protected] => xxxxxxxxxxxxx
            [redirectUri:protected] => http://localhost/fuseddocs/public/infusionsoft/auth/redirect
            [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] => xxxxxxxxxxxxx
                    [refreshToken] => xxxxxxxxxxxxxxx
                    [endOfLife] => 1503940493
                    [extraInfo] => 
                )

        )

    [where:protected] => Array
        (
            [id] => 320
            [optional_properties] => custom_fields,job_title
        )

    [optionalProperities:protected] => Array
        (
        )

    [attributes:protected] => Array
        (
        )

    [hidden:protected] => Array
        (
        )

    [visible:protected] => Array
        (
        )

    [appends:protected] => Array
        (
        )

    [casts:protected] => Array
        (
        )

)

This is the object structure before the call is sent. But when the data si given the custom fiels is empty

@Rohan_Jalil,

The code you posted is using the XML-RPC. I’m not familiar with using the api files with the REST implementation though I have heard there is some support for that I haven’t seen how that would work, but the standard api objects are difinitely XML-RPC. We usually just cURL out to REST.

@John_Borelli this is not using xml rpc this is using rest api. Here is the contact function

  /**
     * @return \Infusionsoft\Api\ContactService
     */
    public function contacts($api = 'rest')
    {
        if ($api == 'xml') {
            return $this->getApi('ContactService');
        }

        return $this->getRestApi('ContactService');
    } 

since I’m not passing anything it is by default using restapi

but this:

infusionsoftService->contacts()->get()

is

@John_Borelli Well I have shared you sdk implementation.

HEre is the getRestApi function

  public function getApi($class)
    {
        $class = '\Infusionsoft\Api\\' . $class;

        if ( ! array_key_exists($class, $this->apis)) {
            $this->apis[$class] = new $class($this);
        }

        return $this->apis[$class];
    }


/**
     * Returns the requested class name, optionally using a cached array so no
     * object is instantiated more than once during a request.
     *
     * @param string $class
     *
     * @return mixed
     */
    public function getRestApi($class)
    {
        $class = '\Infusionsoft\Api\Rest\\' . $class;

        return new $class($this);
    }

Ok, so you’re using a combination of the two. I can see why you would need to do that as some things aren’t available with RPC as they are with REST (but also the vice versa). The fields you are trying to get using the RPC don’t exist in that api context. So, for example, this code:

$obj = $this->infusionsoftService->contacts()->where([
‘id’ => $singleData->id,
‘optional_properties’ => ‘custom_fields,job_title’
]);

is not valid. you’re calling an xml-rpc method and the optional_properties field doesn’t exist in that api context. That field is specific ONLY to the REST implementation.

@John_Borelli ahan I see. But is there any way to get all the custom keys with the retrieval of the contact list ??

@Rohan_Jalil,

If you mean the custom fields, that would be passed with the requested field map using the xml rpc. You would precede any custom field names with an underscore and the names must match the database names listed in your app.

But if I need to do it using rest api then what should I do. I tried to retrieve a single record using with and find method and that worked fine for me in the rest api

Here’s how I tried to retrieve the data for a single record in rest api and this worked

$obj = $this->infusionsoftService->contacts()->with('custom_fields,job_title');

            $data =  $obj->find($singleData->id);

But is there no way of retrieving all of the data with their custom keys using a rest api. That would be a great help because I need to make a generic system. If I keep my intermixing with rest and xml then it would become difficult

If you’re calling with or find then those methods are xml rpc. passing rest fields to them will not work. Your primary confusion here is that you are getting the two implementations mixed together.

Hi @Rohan_Jalil,

You can get a Contact’s custom fields using Retrieve a Contact with custom_fields included in the optional_properties parameter.

For example, to retrieve Contact #13, with custom fields, your request URL would look like: https://api.infusionsoft.com/crm/rest/v1/contacts/13?optional_properties=custom_fields.

You can accomplish the same using the PHP SDK (example usage here):

$infusionsoft->contacts()->with('custom_fields')->find(13);

@mike.christianson Thanks but yes I know of that.

The thing I want to do is to get the list of employes with their custom keys. Not just one contact but get all the contacts with their custom keys.

Is it possible or do I have to make use of Retrieve a Contact implementation to get the custom keys ?