I read answer here How to create interpersonal documents (PDF Files) and how to attach them into email using a SFTP server? and I'm trying to do what Gortonington suggested and send public URL created in SF (create public link functionality for files) to the customer, but I'm unable to do that. Since there will be button on record page 'Send PDF to Customer' this has to be done via API.
I will write down thigs that I created/tested/tried.
- Created DE that includes DocumentName (PrimaryKey), PublicURL (Public URL from SF, this needs to be in email), Contact(field I used to link with Contact ID and create relationship)
- Created email with AMPScript that includes logic to pull correct URL from DE (I tried two versions)
- Created triggered email and picked one created in step 2 to use in sends
- Tested sending email and version 1 worked but only when I send it manually from MC
Do with API after button is clicked:
- Get token from Marketing Cloud
- Create Data Extension record that includes DocumentName, Contact (customers email) and PublicUrl from SF
- Send triggered email (https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/messageDefinitionSends.html)
These are my 2 AMPscript versions:
version 1:
%%[
var @PublicURL, @subscriberKey, @subject
// subscriber key send via API
set @subscriberKey = AttributeValue("_SubscriberKey")
//pull PublicURL filed from DE
set @PublicURL = Lookup("DocumentPDF_TestDE","PublicURL","Contact", @subscriberKey )
//pull Document Name to be used in subject
set @subject = Lookup("DocumentPDF_TestDE","DocumentName","Contact", @subscriberKey )
]%%
Hello!
Download Document PDF : <a href="%%=RedirectTo(@PublicURL)=%%"
// in subject of email I have
%%=v(@subject)=%%
This first version worked while testing in MC, but not when I try to send email via API.
This is JSON Im sending with POSTMAN (same result when making callout from test org)
{
"From" : {
"Name" : "Srdjan Milankov",
"Address" : "[email protected]"
},
"To" : {
"SubscriberKey" : "customer's email",
"Address" : "same as subscriberKey",
}
}
And this is response:
{
"requestId": "071d6f22-0cca-4bfd-9be6",
"responses": [
{
"recipientSendId": "071d6f22-0cca-4bfd-9be6",
"hasErrors": false,
"messages": [
"Queued"
]
}
]
}
I can see in MC that triggered send is queued but it ends up in 'Errored' every time, and I'm not sure what is going on since test send worked just fine. My only guess is that some informations are missing when I'm trying to send it via API.
One more potential issue is that one customer can have many documents(I linked Contact ID to Contact field in DE with one to many) and with lookup I will always pull same record, there are no additional filters, so I tried version 2 of AMPScript logic.
version 2
%%[
var @PublicURL, @subscriberKey, @subject
set @documentName = AttributeValue("_DocumentName")
set @PublicURL = Lookup("DocumentPDF_TestDE","PublicURL","DocumentName", @documentName)
]%%
Hello!
Download Document PDF : <a href="%%=RedirectTo(@PublicURL)=%%"
// in subject of email I have
%%=v(@documentName)=%%
This is JSON request:
{
"From" : {
"Name" : "Srdjan Milankov",
"Address" : "[email protected]"
},
"To" : {
"SubscriberKey" : "customer's email",
"Address" : "same as subscriberKey",
//document name that is used to create DE record before this API call
"DocumentName": "some document name"
}
}
I read online that you can pass parameters via API in contact information when sending email but it does not work.
Also tried wrapping "DocumentName" in "ContactAttributes" but still same result. Triggered send is queued but end's up as 'Errored'.
AttributeValue("_DocumentName")
should beAttributeValue("DocumentName")
. in your email. Needs to match the DE column and the payload attribute name.