400 Bad Request Python

I’m building out a call to add existing contacts to a list, but I’m having some issue just getting the list without getting a 400 error.

This is what I currently have:

def hubspot_read_list(emails, app_download):
url = “https://api.hubapi.com/contacts/v1/lists/30/add?hapikey=OUR_KEY”
jsond = {
“emails”: [
“test123@gmail.com”
],
“app_download”: [
True
]
}
data = json.dumps(jsond)
req = urllib2.Request(url, data, {‘Content-Type’:‘application/json’, ‘Accept’:‘application/json’})
content = urllib2.urlopen(req).read()

Here’s the POST for all contacts, which is connecting to the Hubspot portal correctly

def hubspot_add(email, fname, lname, goal, wink_status):

url = "https://api.hubapi.com/contacts/v1/contact?hapikey=OUR_KEY"
jsond = {
	"properties": [
		{
 			"property": "email",
 			"value": email
		},
		{
			"property": "firstname",
			"value": fname
		},
		{
			"property": "lastname",
			"value": lname
		},
		{
			"property": "goal",
			"value": goal
		},
		{
			"property": "wink_status",
			"value": wink_status
		},
		{
			"property": "app_download",
			"value": True
		}
	]
}
data = json.dumps(jsond)
req = urllib2.Request(url, data, {'Content-Type': 'application/json'})
content = urllib2.urlopen(req).read()

Hi @keilahoover, which endpoint are you using? If you’re simply looking to add contacts to a list, you should be using this one: https://developers.hubspot.com/docs/methods/lists/add_contact_to_list. This endpoint does not accept properties like you’re formatting above. It should only have the emails or vids array in the body, and not the app_download property.

Your body looks like you’re trying to create a contact, then add them to a list where contact’s have the app_download property equal to true. If this is the case, I’d just create an active list in HubSpot with te condition that app_download is equal to true, then create contacts using the contacts API with the app_download property included in the JSON body

Please clarify your goals if I’m off base. Thanks!

That latter suggestion worked perfectly. Thank you!

Great to hear! Glad you got it set up properly
slight_smile.png