APIs & Integrations

pcrivera21
Member

How to mention a user in note using API

Hi Guys!

Is it possible to do in webhook for mentioning the name of a user in the note of the contact lead?
Example:

0 Upvotes
14 Replies 14
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

How to mention a user in note using API

Hi @Paul_Rivera,

I’m glad to hear it’s working! I was incorrect in my example; the type should be TASK. I’ve corrected my previous post for posterity. Regarding your timestamp question; the timestamps are just in milliseconds, so you’re correct that it’s just a timestamp in seconds multiplied by 1000. I’m not very familiar with PHP, but this stack overflow topic I found seems to point to the microtime() method:

How to get current time in milliseconds in PHP?

php, time, milliseconds

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

How to mention a user in note using API

Hi @Paul_Rivera,

Times in HubSpot are formatted as millisecond unix timestamps, which is why the timestamp I included is 13 characters long. The developer doc below has some more info on that. The reminders array is just a field in the metadata, so you should be able to create a task engagement like this:

{
    "engagement": {
        "active": true,
        "ownerId": 1,
        "type": "TASK",
        "timestamp": 1409172644778
    },
    "associations": {
        "contactIds": [2],
        "companyIds": [ ],
        "dealIds": [ ],
        "ownerIds": [ ]
    },
    "metadata": {
    "body": "This is the body of the task.",
    "subject": "Task title",
    "status": "NOT_STARTED",
    "reminders": [
        1513018800000
    ]
  }
}

Here’s the doc for creating an engagement, which is where I pulled this example JSON:

Create an Engagement | Engagements API

POST /engagements/v1/engagements - Create an engagement via the HubSpot API.

edit: corrected the engagement type from NOTE to TASK

pcrivera21
Member

How to mention a user in note using API

Hi @Derek_Gervais!
It works now. thank you for the support! 😃
One more thing how do you do the 13 numbers format? are you multiplying it in 1000?
One of the examples I have seen is “1513142777166”.
How can I convert that to date format?

0 Upvotes
pcrivera21
Member

How to mention a user in note using API

@Derek_Gervais
Still, it does not work.
Should the type be “NOTE”?
Here’s my code:

$taskforCreatingNote = array(
    "engagement" => array(
        "active"=>true,
        "ownerId"=>intval($ownerId_from_db),
        "type"=>"NOTE",
        "timestamp"=>1513143606000
    ),
    "associations"=>array(
        "contactIds"=>array(intval($contactId)),
        "companyIds"=>array(intval($companyId)),
        "dealIds"=>array(),
        "ownerIds"=>array()
    ),
    "metadata" => array(
        "body"=>$taskDescription,
        "subject"=>$taskSubject,
        "status"=>"NOT_STARTED",
        "reminders"=>array(1513144206000)
    )
);
$taskforCreatingNoteJson = json_encode($taskforCreatingNote);
$note_url = "https://api.hubapi.com/engagements/v1/engagements?hapikey=$hubspotApiKey";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $note_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $taskforCreatingNoteJson);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

How to mention a user in note using API

Hi @Paul_Rivera,

You shouldn’t need to include a scheduledTask field when creating a task. Instead, try including a reminders array in the task’s metadata, like this:

"reminders": [
    1513018800000
]
0 Upvotes
pcrivera21
Member

How to mention a user in note using API

@Derek_Gervais
why do you have 13 numbers of timestamp?
Can you also send the correct JSON or PHP array format to use and create a Task reminder to notify the owner through mobile?

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

How to mention a user in note using API

Hi @Paul_Rivera,

Tasks are just engagements, so you’d still need to use the Engagements API. The engagement type would be TASK, and the doc below has details on the structure of task engagements:

Engagements overview

An overview of engagements and the Engagements API

pcrivera21
Member

How to mention a user in note using API

Please check my code because it does not work.
Here’s my code:

Blockquote
$taskforCreatingNote = array(
“engagement” => array(
“active”=>true,
“type”=>“TASK”,
“timestamp”=>strtotime($now),
“ownerId”=>intval($ownerId_from_db)
),
“associations”=>array(
“contactIds”=>array(intval($contactId)),
“companyIds”=>array(intval($companyId))
),
“scheduledTasks”=>array(
“engagementType”=>“TASK”,
“taskType”=>“REMINDER”,
“timestamp”=>$remind_time
),
“metadata” => array(
“body”=>$taskDescription,
“status”=>“NOT_STARTED”,
“subject”=>$taskSubject
)
);
$taskforCreatingNoteJson = json_encode($taskforCreatingNote);
$note_url = “https://api.hubapi.com/engagements/v1/engagements?hapikey=$hubspotApiKey”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $note_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $taskforCreatingNoteJson);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/json’));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);

0 Upvotes
pcrivera21
Member

How to mention a user in note using API

@Derek_Gervais please respose.

0 Upvotes
pcrivera21
Member

How to mention a user in note using API

@Derek_Gervais I can’t find in the docs you gave how to add task reminder time for creating task. Thanks

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

How to mention a user in note using API

Hi @Paul_Rivera,

It’s not currently possible to trigger in-app notifications based on @ mentions or assignments, but you might consider creating a task engagement and setting a date for the reminder; this will send an in app task notification and and email notification (depending on the user’s settings).

pcrivera21
Member

How to mention a user in note using API

@Derek_Gervais Where in API can I find to create a task and send a notification to the user?

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

How to mention a user in note using API

Hi @Paul_Rivera,

While it’s possible to create an @ mention in an engagement, the notification(s) that are sent for @ mentions are based on their creation in the UI. @ mentions created via the API will not trigger notifications, and therefore aren’t recommended.

pcrivera21
Member

How to mention a user in note using API

Thank you for the response.
What do you suggest for in-app notification?

0 Upvotes