How to lookup contact ID / associate based on email. Create a new one if one isn't there.

Regular Contributor

Hello, I am very new to coding and API in general. 

 

Using Postman, I was successfully able to create a task with the API documentation and associate the task to a contact. 

 

However, I was only able to associate this task to the contact because I knew the ContactID. 

 

What if I don't know the ContactID? What code needs to be written to find the contact. What if it can't find the contact, can it create one if I provide other details?

 

 

 

{
    "engagement": {
        "active": true,
        "ownerId": 1,
        "type": "TASK",
        "timestamp": 1604811446969
    },
    "associations": {
        "contactIds": [801],
        "companyIds": [ ],
        "dealIds": [ ],
        "ownerIds": [ ],
		"ticketIds":[ ]
    },
    "metadata": {
    "body": "This is the body of the task.",
    "subject": "Your Customer Requested a Meeting from a recent Marketing Activity",
    "status": "NOT_STARTED",
    "forObjectType": "CONTACT"
  }
}

 

 

Reply
0 Upvotes
3 Replies 3
Advisor | Diamond Partner

Hi @shaebert 

 

Just insert a contact with the same email, if the contact exist you will have a 409 error code and the id will be returned inside the error message (catch it with this regex : /ID: ([0-9]+/ ), if the contact doesn't exist it will be inserted

hsSign_smaller.png

 

 

 

Reply
0 Upvotes
Regular Contributor

Your response seems simple in concept, however, I don't have the skills/knowledge to perform that task. To create a contact is a separate endpoint/path right? So I would have to use the contact API and engagements API together somehow? I was guessing that I had to put some code where the "xxx" is below to populate a contactID when given an email address. 

 

   },
    "associations": {
        "contactIds": [xxx],
    

 

Reply
0 Upvotes
Advisor | Diamond Partner

Hi @shaebert ,

I can help you with your code ,

  • do you want to make a script that request the api endpoint or use the sdk ?
  • Which programming langugage are you most confortable with ?

 

hsSign_smaller.png