Optinally overwrite Title/Subject of a notification

Hi

i need to make the titles of notifications (Subject in E-Mail) dynamic. In other words: I want to have the default title defined in the Designer and be able to overwrite optionally via Send-API Call.

The API Docs say, that might be possible via (JSON-Path) $.message.content.title.

Looking at the PHP-Client, the sendNotification() Method (I’m using) doesn’t use the same JSON Body as described in the docs :confused: And there seems to be no way to provide “content.title”.

There’s a nother method sendEnhancedNotification() wich allows me to use the same JSON body as decribed in the docs … BUT: This requires me to specify the template-id, wich i don’t have, because we’re mapping Events to Templates and send Notifications via the Event Name (not the Template ID).

So: How can i send an Notification via API with only specifying an Event-Name, the Recipients Data and with an optional Title/Subject that overrides the title from the Designer?

Thanks in Advance

Thank you for reaching out!

The first parameter of the sendEnhancedNotification method of the PHP SDK, is the Message object.

See here for the entire Message Object Spec:

You can pass an Event Mapping as the value to the message.template property, and you can pass the recipient data as the value of the message.to property.

Now as for the Subject line. The best way to do this is to include the dynamic data for your subject line as a channel level override. If this data is present in the SDK call, then it will override the default subject line that is saved as part of your Notification Template.

Here is a JSON example of a Message object with a channel level override for the subject. Note that I am also passing the Event Mapping as a value to the message.template property:

{
    "message":{
        "template": "MY_EVENT_MAPPING",
        "to":{
            "user_id": "abc-123",
            "email": "address@email.com"
        },
        "data":{
            "name":"TEST"
        },
        "channels":{
            "email":{
                "override":{
                    "subject":"NEW_SUBJECT"
                }
            }
        }
    }
}

You can learn more about channel level overrides for the email channel here: Email Notification Providers | Courier Docs

Please let us know if you have any other questions.

1 Like

Thanks a lot!

I didn’t expect the template parameter to accept an event. (And didn’t read it, my bad ^)