# Not getting custom key when retrieving data

**URL:** <https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307>\
**Category:** API Q&A\
**Created:** [August 25, 2017, 10:38am UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307 "2017-08-25T10:38:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rohan\_Jalil](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Rohan\_Jalil](https://integration.keap.com/u/Rohan_Jalil)\
**Post date:** [August 25, 2017, 10:38am UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/1 "2017-08-25T10:38:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JustinHandley](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/justinhandley/32/1598_2.png) [@JustinHandley](https://integration.keap.com/u/JustinHandley)\
**Post date:** [August 25, 2017, 12:29pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/2 "2017-08-25T12:29:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Rohan\_Jalil](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Rohan\_Jalil](https://integration.keap.com/u/Rohan_Jalil)\
**Post date:** [August 27, 2017, 7:52am UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/3 "2017-08-27T07:52:02Z")

</div>

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()

```

---

<div class="post-metadata">

**Author:** ![Rohan\_Jalil](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Rohan\_Jalil](https://integration.keap.com/u/Rohan_Jalil)\
**Post date:** [August 28, 2017, 8:03am UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/4 "2017-08-28T08:03:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rohan\_Jalil](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Rohan\_Jalil](https://integration.keap.com/u/Rohan_Jalil)\
**Post date:** [August 28, 2017, 9:39am UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/5 "2017-08-28T09:39:54Z")

</div>

anyone any help ??

---

<div class="post-metadata">

**Author:** ![JustinHandley](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/justinhandley/32/1598_2.png) [@JustinHandley](https://integration.keap.com/u/JustinHandley)\
**Post date:** [August 28, 2017, 1:26pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/6 "2017-08-28T13:26:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rohan\_Jalil](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Rohan\_Jalil](https://integration.keap.com/u/Rohan_Jalil)\
**Post date:** [August 28, 2017, 1:29pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/7 "2017-08-28T13:29:14Z")

</div>

@JustinHandley

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

---

<div class="post-metadata">

**Author:** ![JustinHandley](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/justinhandley/32/1598_2.png) [@JustinHandley](https://integration.keap.com/u/JustinHandley)\
**Post date:** [August 28, 2017, 1:49pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/8 "2017-08-28T13:49:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Rohan\_Jalil](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Rohan\_Jalil](https://integration.keap.com/u/Rohan_Jalil)\
**Post date:** [August 28, 2017, 1:52pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/9 "2017-08-28T13:52:02Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![John\_Borelli](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/john_borelli/32/11880_2.png) [@John\_Borelli](https://integration.keap.com/u/John_Borelli)\
**Post date:** [August 28, 2017, 1:52pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/10 "2017-08-28T13:52:12Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Rohan\_Jalil](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Rohan\_Jalil](https://integration.keap.com/u/Rohan_Jalil)\
**Post date:** [August 28, 2017, 1:54pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/11 "2017-08-28T13:54:41Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![John\_Borelli](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/john_borelli/32/11880_2.png) [@John\_Borelli](https://integration.keap.com/u/John_Borelli)\
**Post date:** [August 28, 2017, 1:56pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/12 "2017-08-28T13:56:15Z")

</div>

but this:

infusionsoftService-\>contacts()-\>get()

is

---

<div class="post-metadata">

**Author:** ![Rohan\_Jalil](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Rohan\_Jalil](https://integration.keap.com/u/Rohan_Jalil)\
**Post date:** [August 28, 2017, 1:59pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/13 "2017-08-28T13:59:35Z")

</div>

@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);
    }

```

---

<div class="post-metadata">

**Author:** ![John\_Borelli](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/john_borelli/32/11880_2.png) [@John\_Borelli](https://integration.keap.com/u/John_Borelli)\
**Post date:** [August 28, 2017, 2:41pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/14 "2017-08-28T14:41:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rohan\_Jalil](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Rohan\_Jalil](https://integration.keap.com/u/Rohan_Jalil)\
**Post date:** [August 28, 2017, 3:01pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/15 "2017-08-28T15:01:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![John\_Borelli](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/john_borelli/32/11880_2.png) [@John\_Borelli](https://integration.keap.com/u/John_Borelli)\
**Post date:** [August 28, 2017, 3:16pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/16 "2017-08-28T15:16:04Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Rohan\_Jalil](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Rohan\_Jalil](https://integration.keap.com/u/Rohan_Jalil)\
**Post date:** [August 28, 2017, 3:28pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/17 "2017-08-28T15:28:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![John\_Borelli](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/john_borelli/32/11880_2.png) [@John\_Borelli](https://integration.keap.com/u/John_Borelli)\
**Post date:** [August 28, 2017, 3:58pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/18 "2017-08-28T15:58:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mike.christianson](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/mike.christianson/32/74_2.png) [@mike.christianson](https://integration.keap.com/u/mike.christianson)\
**Post date:** [August 28, 2017, 4:55pm UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/19 "2017-08-28T16:55:43Z")

</div>

Hi @Rohan_Jalil,

You can get a Contact’s custom fields using [Retrieve a Contact](https://developer.infusionsoft.com/docs/rest/#!/Contact/loadUsingGET) 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](https://github.com/infusionsoft/infusionsoft-php/blob/master/samples/addWithDupCheck.php#L58)):

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

```

---

<div class="post-metadata">

**Author:** ![Rohan\_Jalil](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@Rohan\_Jalil](https://integration.keap.com/u/Rohan_Jalil)\
**Post date:** [August 29, 2017, 5:42am UTC](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307/20 "2017-08-29T05:42:14Z")

</div>

@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 ?

[Next page](https://integration.keap.com/t/not-getting-custom-key-when-retrieving-data/12307.md?page=2)
