Cannot Create A New Contact

Hello fellow API’ers looking for some assistance. please see the following block of error response message:

{ message: 'Email Field is invalid, Address Field is invalid, Unknown sub-resource Region is invalid, Field is invalid' }

This is the response that I continually receive when I attempt to send a new contact into my account throught the REST API using NODE.js. Here is the request that I am making:

request.post({url: "https://api.infusionsoft.com/crm/rest/v1/contacts",json:true, body:
{
	"given_name": customer.fname + " " + customer.lname,
	"email_addresses": [
		{
			"email": customer.email
		}
	],
	"phone_numbers": [
		{
			"number": customer.phone1
		}
	],
	"addresses": [
		{
			"line1": customer.address,
			"zip_code": customer.zip,
			"locality": customer.city,
			"region": customer.state,
			"country_code": "USA"
		}
	],
	"email_opted_in": true,
	"custom_fields":[
		{
			"content":{
				"officeID": subscription.officeID
			},
			"id": 1
		},
		{
			"content": {
				"frequency": subscription.serviceType
			},
			"id": 2
		},
		{
			"content": {
				"contractLength": ((subscription.contractValue - (subscription.initialQuote - subscription.initialDiscount)) / subscription.recurringCharge) + " Services"
			},
			"id": 3
		},
		{
			"content": {
				"recurringPrice": subscription.recurringCharge
			},
			"id": 4
		}
	]
},
headers:{
	'Authorization': 'Bearer ' + accessToken,
	'Accept': "application/json",
	"Content-Type": "application/json"
}

}, function(err, res, body){
});

I could really use some help on this one. Let me know if there are any questions and I will answer best I can!

** UPDATE ** HERE IS THE NEW CODE

request.post({url: "https://api.infusionsoft.com/crm/rest/v1/contacts",json:true, body:
{
	"given_name": customer.fname + " " + customer.lname,
	"email_addresses": [
		{
			"email": customer.email,
			"field":"EMAIL1"
		}
	],
	"phone_numbers": [
		{
			"number": customer.phone1
		}
	],
	"addresses": [
		{
			"country_code": "USA",
			"field":"BILLING",
			"line1": customer.address,
			// "line2":"",
			"locality": customer.city,
			"zip_code": customer.zip,
			"region": customer.state
		}
	],
	"email_opted_in": true,
	"custom_fields":[
		{
			"content":{
				"officeID": subscription.officeID
			},
			"id": 1
		},
		{
			"content": {
				"frequency": subscription.serviceType
			},
			"id": 2
		},
		{
			"content": {
				"contractLength": ((subscription.contractValue - (subscription.initialQuote - subscription.initialDiscount)) / subscription.recurringCharge) + " Services"
			},
			"id": 3
		},
		{
			"content": {
				"recurringPrice": subscription.recurringCharge
			},
			"id": 4
		}
	]
},
headers:{
	'Authorization': 'Bearer ' + accessToken,
	'Accept': "application/json",
	"Content-Type": "application/json"
}

}, function(err, res, body){
});

And now the error that I am receiving is only this:
{message: 'Field is invalid'}

It does not even say what the “Field” is that is throwing the error! In testing I have completely removed the
"email_opted_in"
field and the
"custom_fields"
section and it still throwing the same error.

I still need some solid help with this one. it took me a few hours to get this far… a little push can be very useful right about now…

Hi @Riley_Worthen, there’s also a field property for phone numbers. Try adding "field": "PHONE1" to your phone number object.

1 Like

Thank you so much for responding!

I Actually just figured that one out, but now I am getting another error. Here it is:

{ message: 'Failed to convert property value of type [java.util.LinkedHashMap] for property \'customFields[null]\'; nested exception is java.lang.NullPointerException' }

This one is due to the custom_fields section, but I dont know what it wants me to do.

I honestly dont believe that this is the correct way to add a custom field… In fact I am not entirely sure what is even supposed to be entered into the "content" object of the "custom_fields"section, The API docs dont say anything in regards to what is supposed to be within the {} of the content.

All that I know is that when I create a new customer, I am being required to add an officeID, frequency of service, contract length and our recurring price. Now where or how that information needs to be added through the API is a mystery to me.

I have also not been able to create/update contact by any means using custom_fields parameter through the API. Every time I include any custom_fields: parameter I get the the Java failed to convert property value error message also!! And there is no clear definition of how to pull contact custom field ID’s from the REST API. So I am guessing on the custom field ID’s to even try to get anything to work, but nothing is working with custom_fields that I can tell for update/create contact.

Here is a sample of my create/update contact JSON:
{“duplicate_option”: “EmailAndName”,“addresses”: [{ “country_code”: “USA”, “field”: “BILLING”, “line1”: “XXXX XXX XXXX”, “line2”: “”, “locality”: “Denver”, “region”: “Colorado”, “zip_code”: “80219”}],“email_addresses”: [{“email”: “xxxxxxxxx@yahoo.com”,“field”: “EMAIL1” }], “given_name”: “XXXX”,“phone_numbers”: [{“field”: “PHONE1”, “number”: “11111111111”}] ,“custom_fields”:[{“id”:“1”,“content”: “CANYOUSEEME”}] }

And here is the response:
{
“message”: “Failed to convert property value of type [java.lang.String] for property ‘customFields[null]’; nested exception is java.lang.NullPointerException”
}

IF I remove the custom_fields paramater (,“custom_fields”:[{“id”:“1”,“content”: “CANYOUSEEME”}] ), the API call is successful.

HAS ANYONE ACTUALLY HAD SUCCESS USING THE API AND custom_fields???

@Nate_Mecham I think that I might have found something of interest. In my main infusionsoft account, there is a place where you can create a custom field and I think that this is where you have to pre-define the names of the custom fields before you can be allowed to use the call for the API. Here is the link to the page that I found.
create-custom-field
&
API database info for custom fields

I am working on trying to test what these pages teach, and I will let you know when I make an attempt with it.

We have created several custom fields in the admin->settings for contact:
Here are 2 of them, the first 2 created:

Dealer Number Text
Agent Name Name
(data from:
https://xd418.infusionsoft.com/Admin/custom/manageCustomFields.jsp?table=Contact
)

Here is what the “View the field database names (for the API)” area shows for these:

"----------------
Custom Field Details for the Contact Record

NOTE: You must prepend custom field database names with an underscore when accessing them through the API.
EXAMPLE: _SomeField

Label Type Database Name
Dealer Number Text DealerNumber
Agent Name Name AgentName
-----"
However, you cannot reference these custom fields using ID: _DealerNumber or _AgentName, according to the API docs it has to be the actual ID, which I have NO IDEA of how to get to as there is no documentation for this that I can find. Some of the forum posts just reference back to the REST API documentation, which does not specify how to do this. I have not been able to find the created custom_field ID’s anywhere.

And even if I did have the correct ID, the custom_fields is failing with the:
“message”: “Failed to convert property value of type [java.lang.String] for property ‘customFields[null]’; nested exception is java.lang.NullPointerException”
Error anyway…
So, until I can resolve the java error to even pass in a custom_fields paramater through the incoming API call, I am not sure what to do here.

Any suggestions?

Yeah because that error does not have anything to do with the id… The error is regarding the "content" object that the api says that we need to have. We really need to get a response from one of the infusionsoft API developers in here. I have tried countless things to get it to function. My past attempts are with their corresponding errors:
1.
"content":"some string"

{ message: 'Failed to convert property value of type [java.lang.String] for property \'customFields[null]\'; nested exception is java.lang.NullPointerException' }

"content":{"_some field":"what the field should be"}

{ message: 'Failed to convert property value of type [java.util.LinkedHashMap] for property \'customFields[null]\'; nested exception is java.lang.NullPointerException' }

"content":[{"_some field":"what the field should be"}]

{ message: 'Failed to convert property value of type [java.util.ArrayList] for property \'customFields[null]\'; nested exception is java.lang.NullPointerException' }

No matter what you put next to the content field, it seems to throw this error…

Something may be amiss here. or I may just be blind to something obvious, which I doubt…

OK, so need to find a way to get by the java error and find the ID’s of the custom_fields.

I have been looking all around the internet to find material that could help with this situation, andI have found a whole bunch of stuff yet the whole bunch of stuff ALL rely on one API query that does not even exist on the API docs!!! I have found at least 4-5 locations on the internet between github, stackoverflow and even here on community.infusionsoft.com that all give this link:

https://developer.infusionsoft.com/docs/rest/#!/Contact/listCustomFieldsUsingGET

How are we even supposed to make this query!? There are no docs for it, but there sure is a link!

This query would give us at least the ID for the custom fields that we would want to insert into, but that still does not solve the problems that I have previously stated regarding the contact field.

Hi Nate, Riley. It seems this post may need to be split into 2 separate posts? unless they are the same issue. @Riley_Worthen, I believe this may be a type error (from first glance). Can you please post the most recent request body that you used?

@Nate_Mecham the url should be Keap REST API.

request.post({url: "https://api.infusionsoft.com/crm/rest/v1/contacts",json:true, body:
	{
		"given_name": customer.fname + " " + customer.lname,
		"email_addresses": [
			{
				"email": customer.email,
				"field":"EMAIL1"
			}
		],
		"phone_numbers": [
			{
				"field":"PHONE1",
				"number": customer.phone1
			}
		],
		"addresses": [
			{
				"country_code": "USA",
				"field":"BILLING",
				"line1": customer.address,
				"locality": customer.city,
				"zip_code": customer.zip,
				"region": customer.state
			}
		],
		"opt_in_reason":"They are now a pest routes customer",
		"email_opted_in": true,
		"custom_fields":[
			{
				"id": 24, // totally random id numbers
				"content": subscription.officeID
			},
			{
				"id": 25,
				"content": subscription.serviceType
			},
			{
				"id": 26,
				"content": ((subscription.contractValue - (subscription.initialQuote - subscription.initialDiscount)) / subscription.recurringCharge) + " Services"
			},
			{
				"id": 27,
				"content": subscription.recurringCharge
			}
		]
	},
	headers:{
		'Authorization': 'Bearer ' + accessToken,
		'Accept': "application/json",
		"Content-Type": "application/json"
	}
}, function(err, res, body){
});

ok, thanks, I tried to find the /contacts/model in the API documentation yesterday and couldn’t find it, but may have been trying /contact/model …
What about the java errors when posting custom_fields?

GUESS WHAT

the java errors go away when you place the correct ID.

I just successfully posted the data into the custom fields.

FINAL THOUGHTS:

the API request that you just posted to me @Carlos_Ochoa probably should be made slightly more clear in the DOCS. This was a little overwhelming to get just this little API call to function correctly. Besides that, I am very greatful for the assistance!

Excellent!. After (the long process of) finding the correct ID’s the Below code posted successfully:

{“duplicate_option”: “EmailAndName”,“addresses”: [{ “country_code”: “USA”, “field”: “BILLING”, “line1”: “XXXX XXX XXXX”, “line2”: “”, “locality”: “Denver”, “region”: “Colorado”, “zip_code”: “80219”}],“email_addresses”: [{“email”: “xxxxxxxxx@yahoo.com”,“field”: “EMAIL1” }], “given_name”: “XXXX”,“phone_numbers”: [{“field”: “PHONE1”, “number”: “11111111111”}] ,“custom_fields”:[{“id”:48,“content”: “XXXXXXXXXXX”}] },

which ID 48 was for the DealerNumber in the custom fields area

1 Like

Congrats @Nate_Mecham I felt so ecstatic when I saw the {result: success} !! that feeling of relief. was pretty intense. I imagine so for you as well!

No problem, I am glad you were able to get running! :slight_smile:. I will do my best to go through and update those old link references to the docs. As well I will add a task for the team to look at updating verbiage in the docs themselves.

Carlos