Create Contact using meteor

SOLVE
New Contributor

Hello there,

 

I've been using hotspot to check contacts registered on our plaform using the following code: 

const paramData = { // HubSpot API header for HTTP petitions
			'params': { "hapikey": hapikey }
		};

		HTTP.call('GET', `https://api.hubapi.com/contacts/v1/contact/email/${userEmail}/profile`, paramData, function(error, response) {
			if (error) {
			    doSomething();
			} else {
                            doSomethingElse();

and it works, however if try this with the create contact endpoint

const paramData = { // HubSpot API header for HTTP petitions
			'params': { "hapikey": hapikey }
		};

		HTTP.call('POST', 'https://api.hubapi.com/contacts/v1/contact', paramData, function(error, response) {
			if (error) {
				return console.log(`failed user.createContact API Call: ${error.response.statusCode}, ${error.response.content}`);
			} else {
				console.log("Succesfully created user")
			}
		});

i get the following error

 

 {"status":"error","message":"Any of the listed authentication credentials are missing","correlationId":"a7f187e9-5002-40ed-921e-dbb71bedf5a5","engagement":{"oauth-token":"oauth-token not engaged. OAuth access token not found in request header.","hapikey":"hapikey not engaged. hapikey is not present in query params.","shhkey-v1":"shhkey-v1 not engaged. Shhkey not found in the request header.","vendorkey-gae":"vendorkey-gae not engaged. Vendorkey not found in request headers.","app-cookie":"app-cookie not engaged. App cookie is not present on the request.","internal-cookie":"internal-cookie not engaged. Cookie not found in the request."},"requestId":"d3a52cd1277a7a798c6d3ed43b624088"}

so whatever, I'm just testing and i pass the hapikey in the url and pass this as paramData instead:

 

const data = {
			'headers': {'Content-Type': 'application/json'},
			'body' : {
				'properties': [
					{
						"property": "email",
						"value": "testingapis@hubspot.com"
					},
					{
						"property": "firstname",
						"value": "Adrian"
					},
					{
						"property": "lastname",
						"value": "Mott"
					}
				]
			}
		}

and i get the following error:

 

{"status":"error","message":"Invalid JSON input: No content to map due to end-of-input at line 1, column 0","correlationId":"68408b6d-dad4-4433-80c8-a8364a0989db","requestId":"cc965d8581a796483141e2adfc9de11d"}

which leads me to belive this endpoint takes the parameters in a different structure than the other one. Any help regarding this will be greatly appreciated.

 

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
New Contributor

after a bit of extra research on http.call by meteor i came up with this:

 

{
			'params': { 'hapikey': apikey },
			'headers': {'Content-Type': 'application/json'},
			'content' : JSON.stringify({
				'properties': [
					{
						'property': 'email',
						'value': 'testingapis@hubspot.com'
					},
					{
						'property': 'firstname',
						'value': 'Adrian'
					},
					{
						'property': 'lastname',
						'value': 'Mott'
					}
				]
			})
		}

you were right regarding the quotation differences, which i totally missed, thanks for that!

Reply
0 Upvotes
2 Replies 2
Highlighted
HubSpot Moderator

Hi @lmontana,

 

The "Create a new contact" endpoint will accept a JSON payload with key value pairs exactly in the format you've included in your example. However if there is any issue with the formatting of this payload you are likely to encounter errors.  In this instance you should be getting a 400 response code back which indicates that there is a problem with the data in the request body, including when there are no properties included in the request data.

 

The error you are getting is likely due to an irregularity within the payload you are sending us. One thing I've noticed is the way you've enclosed some attributes with single quotations vs double quotations. I copied the body of your request into Postman to test this and it shows up as an error. Could you try making the same request but using double quotations?

 

For example see below:

 

const data = {
			"headers": {"Content-Type": "application/json'"},
			"body" : {
				"properties": [
					{
						"property": "email",
						"value": "testingapis@hubspot.com"
					},
					{
						"property": "firstname",
						"value": "Adrian"
					},
					{
						"property": "lastname",
						"value": "Mott"
					}
				]
			}

 

Regards,

Jack

 

Jack Coldrick
Solutions Engineer @ HubSpot
Add me on LinkedIn
Highlighted
New Contributor

after a bit of extra research on http.call by meteor i came up with this:

 

{
			'params': { 'hapikey': apikey },
			'headers': {'Content-Type': 'application/json'},
			'content' : JSON.stringify({
				'properties': [
					{
						'property': 'email',
						'value': 'testingapis@hubspot.com'
					},
					{
						'property': 'firstname',
						'value': 'Adrian'
					},
					{
						'property': 'lastname',
						'value': 'Mott'
					}
				]
			})
		}

you were right regarding the quotation differences, which i totally missed, thanks for that!

Reply
0 Upvotes