Can't figure out how to update a contact

While I’m sure it’s just me doing something wrong, I can’t seem to figure out how to update a contact. I’m using REST with the PHP SDK, and it doesn’t throw an error, it just doesn’t work like this.

    $data = array('given_name' => 'Smith');
    $this->infusionsoft->contacts('update',16, $data );

This is the only way I’ve found to not get an error but it doesn’t work. To be honest, I don’t even remember where I found this method (the update as a parameter) as I’ve been looking all over this forum and google.

If I try anything with

$this->infusionsoft->contacts()->update() 

it just tells me

Fatal error: Uncaught Error: Call to undefined method Infusionsoft\Api\Rest\ContactService::update()

Which I can see is true, but that’s what I see on the page https://developer.infusionsoft.com/docs/xml-rpc/#contact-update-a-contact
(I know the link says xml-rpc, but I’m clicking on the PHP tab at the top and it changes to at least look like it could work). I’m assuming this is some older version or something?

If I try the save method from https://github.com/infusionsoft/infusionsoft-php

    $contact->given_name = 'Smith';
    $contact->save();

I get Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: PATCH https://api.infusionsoft.com/crm/rest/v1/contacts/18?access_token=[token] resulted in a 400 Bad Request

I’m sure it’s something dumb, but I’ve wasted too many hours on this already.

Also, how will updating a custom field vary?

TIA

Hi, @Daniel_Strood,

I don’t personally use the REST calls through the XML-RPC, which is available but it seems un-intuitive to me so I either use the XML-RPC calls or REST directly (without the support files).

So let me start by asking some of the basics first.

  • What authentication method are you using? (I'm guessing OAuth but it's not 100% clear at the moment).
  • What are you immediate goals? (there may be an easier approach if you're doing some basics).

Hi John,
Sorry, yes it’s OAuth and that works. I can create a contact no problem like this:

$contact = ['given_name' => 'John', 'family_name' => 'Doe', 'email_addresses' => [$email1]];

What my program is doing is taking orders we get through 3 different squarespace accounts (2 US, 1 CAN), and either updating or creating a contact, and filling in the various custom fields I’ve created related to the purchases such as date, order number, what they bought and other things, along with the standard things like address. Clients can purchase multiple times, so I’m checking to see if they’ve already ordered, and append the fields, instead of creating a new entry.

We also use tags to denote and filter the various products, regions and types of clients, so the app also analyzes the orders to determine which tags need to be applied.

Any suggestions would be appreciated.

Ok, so custom fields are similar with the exception that you must preceed them with an underscore like follows:

$contact = ['given_name' => 'John', 'family_name' => 'Doe', 'email_addresses' => [$email1], '_customFieldName'=>'custom field value'];

Now, the REST implementation does still use the XML-RPC methods for querying the tables. You’ll want to run queries on those tables (for contacts and orders) to determine their existence or not. I’ll leave a link to the table documentation and query methods below:

Table Schema : Click Here
Query Methods : Click Here

For the query methods, look under the Data Services and find the Query method. You can test it in real time using those interactive io docs and confirm the needed parameters.

Interesting, I didn’t realize the REST calls were still going through XML-RPC. Shows how little I actually know what I’m doing.

I was able to get it working, and the only thing I did was change it to using xml:

    $data = array('FirstName' => 'Smith');
    $this->infusionsoft->contacts('xml')->update(16, $data);

And this works. Confirmed it works with custom fields as well. Thanks a lot for your help John, very much appreciated.

REST is still being developed so it doesn’t have all the same calls that the SDK has. So there are a few areas that you’d want to use the XML-RPC for, especially if you end up needing to query a table directly.