Internal error when creating an engagement



I am trying to import a record of customer emails into a hubspot account as part of evaluating hubspot, but hitting an internal error with the API. I am trying to create an engagement record using this python code:

def format_email(email, name):
    if not name:
        return email
        return u'%s <%s>' % (name, email)

data = json.load(open(data_file))
(firstname, lastname) = name_from_data(data)
engagement = { 
    'engagement': {
        'active': False,
        'type': 'EMAIL',
        'timestamp': data['ts'] * 1000,
        'uid': data['msg']['headers']['Message-Id'],
    'metadata': {
        'from': {
            'email': data['msg']['from_email'],
        'to': [format_email(*to) for to in data['msg']['to']],
        'cc': [], 
        'bcc': [], 
        'subject': data['msg']['subject'],
        'html': data['msg']['html'],
        'text': data['msg']['text'],
if firstname:
    engagement['metadata']['from']['firstName'] = firstname
if lastname:
    engagement['metadata']['from']['lastName'] = lastname

connection.send_post_request('/engagements/v1/engagements', engagement)

That always seems to result in an internal error in the hubspot API:

'{"status":"error","message":"internal error","correlationId":"b4b9e236-42a4-4b84-bd96-de84f602e108","requestId":"d21a5da8-1e76-40a8-acf5-c59550ad4b76"}

As far as I can see my data structure matches documented structure. Can anyone see why I get that error?


Hi @wichert

Those errors often point to a formatting issue with the data in the request. Do you have an example of the actual body of the request? Is the data in engagement getting stringified before the request?


Hi @dadams,

This is the exact request data being send:

'{"engagement": {"active": false, "timestamp": 1368214102000, "type": "EMAIL", "uid": "<>"}, "metadata": {"from": {"email": ""}, "cc": [], "text": "This is an example inbound message.\\n", "bcc": [], "to": [""], "html": "<p>This is an example inbound message.</p><img src=\\",\\" height=\\"1\\" width=\\"1\\">\\n", "subject": "This is an example webhook message"}}'

In a more readable form (before serializing as JSON):

{'engagement': {'active': False,
                'timestamp': 1368214102000,
                'type': 'EMAIL',
                'uid': u'<>'},
 'metadata': {'bcc': [],
              'cc': [],
              'from': {'email': u''},
              'html': u'<p>This is an example inbound message.</p><img src="," height="1" width="1">\n',
              'subject': u'This is an example webhook message',
              'text': u'This is an example inbound message.\n',
              'to': [u'']}}


Hi @dadams,

can you see what I’m doing wrong?


@wichert the "to" field in the metadata needs to be an array, not a list:

"to": {
  "email": ""

This isn’t related to the error, but you’ll also want to make sure that you’re including associations with the data, otherwise you won’t actually see the engagement (the engagement will not automatically be associated with a record based on that to field).