How to add custom field values to contact

Can you please let me know how to add custom field values to an existing or new contact ? I did not found any reference on this. Please suggest.

If possible please provide any demo script.

@Vinod_Rath,

There are a few ‘caveats’ with custom field assignment:

First, the name of the custom field is not always what you give it when you set it up. In your admin->settings/custom field list you will find a link like this:

This list will indicate the name to use.

Second, when using the database name, you must precede it with an underscore.

Third, you include this name in your array of fields to update on the contact in the same way you would the FirstName or LastName field only it would be something more like _CustField.

Hope that clears up some of the details.

Thanks @John_Borelli for this. How can i add a value to custom field. Let say we have a custom field named “AmazonEmail” so i need to insert the value to that custom field for all contacts.

No issue @John_Borelli . all clear…thanks

I have one question : some custom fields are created with Order id so i need to update the order table or something else? please suggest.

I’m not quite sure what you’re asking. The fact that an order id is stored on a custom field wouldn’t change anything…it’s just data. However, if you’re saying you’ve created custom fields on the order table (as apposed to the contact table) then when you update an order you would use the custom field for the order table just the same as when you would update a contact custom field on the contact table.

But in table scheme order table is not found.

I have created a tab in order page with custom fields. Please check screenshot here Order Information.png - Google Drive

Yeah, that’s a throwback from early Infusionsoft days. The name of the order table is actually ‘Job’

Can i update that table using contact id or something else ?

I have tried using order id but not working?

You would search the order table for the order id by querying for the contact id (keep in mind you can have more than one order on a contact). Then using the correct discovered order id, you can update the job table with any fields common to the order including the custom fields. If you want the custom field information to be relevant to the contact then you would have to store the custom field on the contact rather than the order (job).

Hi @John_Borelli. I have one question. I have creating a cron job for refreshing access token. and some times it works but after 2-3 days its not working. Can you help me on that. I need access token refreshed every time when it expires. Please let me know so i can share my script here.

If it’s working and then stops then you can only have one of two problems. Either the CRON job isn’t firing for the refresh script to do it’s job or the script isn’t working. So start by posting the script that does the refresh.

cron job working fine. For 1st time i have insert accesstoken to the db then it will refresh See the script below.

<?php $infusionsoft = new \Infusionsoft\Infusionsoft(array( 'clientId' => '', 'clientSecret' => '', 'redirectUri' => '', )); $infusionsoft->setHttpClient(new \Infusionsoft\Http\CurlClient()); $query = mysqli_query($con,"select * from wp_infusionsoft"); $row = mysqli_fetch_array($query,MYSQLI_ASSOC); $token = $row['access_token']; $tokenUnserial = unserialize($token); $infusionsoft->setToken($tokenUnserial); if (isset($_SESSION['token'])) { $infusionsoft->setToken(unserialize($_SESSION['token'])); } // If we are returning from Infusionsoft we need to exchange the code for an // access token. if (isset($_GET['code']) and !$infusionsoft->getToken()) { $infusionsoft->requestAccessToken($_REQUEST['code']); } if ($infusionsoft->getToken()) { //$infusionsoft->refreshAccessToken(); $expired = $infusionsoft->isTokenExpired(); //print_r($expired); if($expired){ $infusionsoft->refreshAccessToken(); } $_SESSION['token'] = serialize($infusionsoft->getToken()); //$token_array = $_SESSION['token']; //print_r($_SESSION['token']); $tokenSerial = $_SESSION['token']; //Store $tokenSerial somewhere and/or begin making API calls $tokenSerial = mysqli_real_escape_string($con,$tokenSerial); mysqli_query($con,'update wp_infusionsoft set access_token="'.$tokenSerial.'" where id=1 '); echo '
';
	print_r($infusionsoft);
	echo '
'; }

I would start by logging. The first thing I would want to see is the actual query so instead of directly placing a string in your mysqli_query do this:

$query=‘update wp_infusionsoft set access_token="’.$tokenSerial.'" where id=1 ';
// write $query to a log file
mysqli_query($con,$query);

I can’t put my finger on it but my mind is telling me that your $_SESSION isn’t persisting but the only way to know is to create a log entry.

ok i will do that. Do you have any example that handle this??

you can just write it to a text file for now. The objective is to just “see” to believe

update wp_infusionsoft set access_token=“O:18:"Infusionsoft\Token":4:{s:11:"accessToken";s:24:"bndhw96a4d6pe4vuzbvtas5t";s:12:"refreshToken";s:24:"z2d6swezeufzp7p6j4ytyen4";s:9:"endOfLife";i:1492524306;s:9:"extraInfo";a:2:{s:10:"token_type";s:6:"bearer";s:5:"scope";s:27:"full|ah244.infusionsoft.com";}}” where id=1 [Info][2017/04/18 07:31:20 guest@122.168.124.144 AmazonOrderItemList.php:130 sendRequest] Making request to Amazon: ListOrderItems