Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a new contact list #64

Closed
davymirfin opened this issue Jan 13, 2021 · 6 comments
Closed

Create a new contact list #64

davymirfin opened this issue Jan 13, 2021 · 6 comments

Comments

@davymirfin
Copy link
Contributor

I think this functionality is missing:

https://legacydocs.hubspot.com/docs/methods/lists/create_list

@davymirfin
Copy link
Contributor Author

@nover is it OK for me to implement this?

@nover
Copy link
Contributor

nover commented Jan 14, 2021

@davymirfin sure, please go ahead!

@davymirfin
Copy link
Contributor Author

davymirfin commented Jan 20, 2021

Hi @nover
It appears to me that the serialization method we currently use for the REST API POST requests that are currently implemented is not appropriate for some of the API calls that are not yet implemented (e.g. for create a new contact list). I am happy to be corrected if I am mistaken.

If I execute the following integration test with my HubSpot API key
public async Task Create_contact_and_get_works()
Below is the REST POST transaction that is implemented to create a contact. Note that the entity properties are serialized as an array of property structs, with property and value fields (this matches the specification as described here https://legacydocs.hubspot.com/docs/methods/contacts/create_contact).

Request sent:

https://api.hubapi.com/contacts/v1/contact?hapikey=xxxxxxxxxxxxxxx
method: POST
{
	"properties": [{
		"property": "email",
		"value": "cba4e81778c0465c80355925be2c90d3@skarp.dk"
	}, {
		"property": "firstname",
		"value": "Mr"
	}, {
		"property": "lastname",
		"value": "Tester"
	}, {
		"property": "company",
		"value": "Damage Inc."
	}, {
		"property": "phone",
		"value": "+45 12345678"
	}, {
		"property": "address",
		"value": "Som street 42"
	}, {
		"property": "city",
		"value": "Appleseed"
	}, {
		"property": "state",
		"value": ""
	}, {
		"property": "zip",
		"value": "2300"
	}]
}

Response code: 200 OK
{
	"vid": 251,
	"canonical-vid": 251,
	"merged-vids": [],
	"portal-id": 9153870,
	"is-contact": true,
	"profile-token": "AO_T-mNgETyrbKRjruLoZxQ_OUuzt3IFnoadM_kI4XoEgZZTf_9ChxqUEQLHwDGMJrioM7V2yCIKiBastBYOZkmYwbTqljGizRXOu5kbVuE7E1ctRpd2EZNEKFDSe0lsnJqtMNNcvRr3",
	"profile-url": "https://app.hubspot.com/contacts/9153870/contact/251",
	"properties": {
		"zip": {
			"value": "2300",
			"versions": [
				{
					"value": "2300",
					"source-type": "API",
					"source-id": null,
					"source-label": null,
					"timestamp": 1611098357491,
					"selected": false
				}
			]
		},
		"firstname": {
			"value": "Mr",
			"versions": [
				{
					"value": "Mr",
					"source-type": "API",
					"source-id": null,
					"source-label": null,
					"timestamp": 1611098357491,
					"selected": false
				}
			]
		},
		"address": {
			"value": "Som street 42",
			"versions": [
				{
					"value": "Som street 42",
					"source-type": "API",
					"source-id": null,
					"source-label": null,
					"timestamp": 1611098357491,
					"selected": false
				}
			]
		},
		"city": {
			"value": "Appleseed",
			"versions": [
				{
					"value": "Appleseed",
					"source-type": "API",
					"source-id": null,
					"source-label": null,
					"timestamp": 1611098357491,
					"selected": false
				}
			]
		},
		"phone": {
			"value": "+45 12345678",
			"versions": [
				{
					"value": "+45 12345678",
					"source-type": "API",
					"source-id": null,
					"source-label": null,
					"timestamp": 1611098357491,
					"selected": false
				}
			]
		},
		"company": {
			"value": "Damage Inc.",
			"versions": [
				{
					"value": "Damage Inc.",
					"source-type": "API",
					"source-id": null,
					"source-label": null,
					"timestamp": 1611098357491,
					"selected": false
				}
			]
		},
		"state": {
			"value": "",
			"versions": [
				{
					"value": "",
					"source-type": "API",
					"source-id": null,
					"source-label": null,
					"timestamp": 1611098357491,
					"selected": false
				}
			]
		},
		"email": {
			"value": "cba4e81778c0465c80355925be2c90d3@skarp.dk",
			"versions": [
				{
					"value": "cba4e81778c0465c80355925be2c90d3@skarp.dk",
					"source-type": "API",
					"source-id": null,
					"source-label": null,
					"timestamp": 1611098357491,
					"selected": false
				}
			]
		},
		"lastname": {
			"value": "Tester",
			"versions": [
				{
					"value": "Tester",
					"source-type": "API",
					"source-id": null,
					"source-label": null,
					"timestamp": 1611098357491,
					"selected": false
				}
			]
		}
	},
	"form-submissions": [],
	"list-memberships": [],
	"identity-profiles": [
		{
			"vid": 251,
			"is-deleted": false,
			"is-contact": false,
			"pointer-vid": 0,
			"previous-vid": 0,
			"linked-vids": [],
			"saved-at-timestamp": 0,
			"deleted-changed-timestamp": 0,
			"identities": [
				{
					"type": "EMAIL",
					"value": "cba4e81778c0465c80355925be2c90d3@skarp.dk",
					"timestamp": 1611098357500,
					"is-primary": true,
					"source": "UNSPECIFIED"
				},
				{
					"type": "LEAD_GUID",
					"value": "66fce4d1-e1e1-4b81-9b04-25b7d2bd8df2",
					"timestamp": 1611098357545,
					"source": "UNSPECIFIED"
				}
			]
		}
	],
	"merge-audits": []
}

However, if we want to create a contact list the API specification requires a different format of serialization as described here https://legacydocs.hubspot.com/docs/methods/lists/create_list.

For example:

{
    "name": "tweeters",
    "dynamic": true,
    "portalId": 62515
}

What the current serialization software would produce this:

{
	"properties": [{
		"property": "name",
		"value": "tweeters"
	}, {
		"property": "dynamic",
		"value": "True"
	}, {
		"property": "portalId",
		"value": "62515"
	}]
}

If I POST a create contact list request using this serialization format I get an error as follows:

https://api.hubapi.com/contacts/v1/lists?hapikey=xxxxxxxxxxxxxxx
{
	"properties": [{
		"property": "name",
		"value": "Test1"
	}, {
		"property": "dynamic",
		"value": "False"
	}, {
		"property": "offset",
		"value": "0"
	}, {
		"property": "has-more",
		"value": "False"
	}]
}

Response code: 400 Bad Request
{
	"status": "error",
	"message": "{\"status\":\"error\",\"message\":\"Every list must have a name.\",\"correlationId\":\"2b21fd78-ed32-42e9-bb35-1b9e5a5d36b3\"}",
	"correlationId": "2b21fd78-ed32-42e9-bb35-1b9e5a5d36b3"
}

Is it possible to change the serialization format by changing a setting? If not we need to decide how to solve the above problem.

Many thanks for your help

@davymirfin
Copy link
Contributor Author

@nover
I see that DataConverters are being used in the serialization but not for deserialization. I note that, in general HubSpot JSON requests tend to have the properties, property, value structure whilst responses have the JSON structure that I need so it appears that I simply need to avoid the DataConverters for both serialization and deserialization. I shall assume that is the correct approach and proceed with that assumption.
I hadn't come across this particular complication before.

@nover
Copy link
Contributor

nover commented Jan 20, 2021

@davymirfin
thanks for your details - I am a bit tired of HubSpots back and forth on both input and output models :) A lot of them use the complicated "property-value" syntax and some don't - this form of inconsistency kills me.

But feel free to implement whatever is needed and use that from your new Create a new contact list call 👍

@nover
Copy link
Contributor

nover commented May 12, 2021

@davymirfin I'm pretty sure this was fixed via your MR #67?

@nover nover closed this as completed May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants