Solved

How to get contact ID from message ID to add supplemental meta-info to a contact who sends a custom channel message

  • 10 December 2022
  • 1 reply
  • 111 views

Badge +2

I’d like to send more data to the custom channel endpoint, like sending more customer data, sending a tag, etc. The endpoint seems like it only receives messages

https://dev.frontapp.com/reference/post_channels-channel-id-incoming-messages

 

I assume I can make additional calls after the conversation exists to perform actions like adding tags, and that I can hit the Contact API endpoints to create/modify the Contact record.

However, I’m hunting through the docs and I can’t find where I can get a contact_id from the message_uid that is returned when I create the message in the custom channel. I can of course create a contact before calling the custom message endpoint, but that fails if the contact exists already, which, maybe that is fine. Ideally the system can send the message, and then I can just grab the contact_id of the contact on that message, and add meta-info after the fact. I can’t even find an endpoint to grab a contact ID by handle, that’s the other strategy to avoid a 429 failure.

 

So question here is:

 

What is the strategy to add supplemental meta-info to a contact who sends a custom channel message? (Email, links, etc.)

 

 

icon

Best answer by Javier - Developer Relations 10 December 2022, 03:07

View original

1 reply

Userlevel 5
Badge +8

So you can use resource aliases to fetch a contact by handle.

 

If you have a contact with ID: crd_123, and email handle jason@example.com both the following calls will return the same data;

 

GET /contacts/crd_123

GET /contacts/alt:email:jason@example.com

 

And they will both return a 404 if the contact can not be found.

 

Again, with the message UID you can use resource aliases with GET /messages/alt:uid:<message_uid> to fetch a message by UID which will return the message including an array of recipient objects; the ID itself isn't provided as it's own field in that payload, but it is contained in the _links.related.contact field of the recipient. Below is an example of what that looks like

GET /messages/alt:uid:<message_uid>

{

  "recipients": [

    {

      "_links": {

        "related": {

          "contact": "https://api2.frontapp.com/contacts/crd_123..."

        }

      },

      "name": "Jason Example",

      "handle": "jason@example.com",

      "role": "from"

    },

    {

      "_links": {

        "related": {

          "contact": "https://api2.frontapp.com/contacts/crd_456..."

        }

      },

      "name": "",

      "handle": "support@example.com",

      "role": "to"

    },

    ...

  ]

}

 

I hope this is helpful!

 

--Jason

Reply