Send public URL from SalesForce via TriggeredSend (Triggered send failed)

ampscriptapimarketing-cloud

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.

  1. 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)
  2. Created email with AMPScript that includes logic to pull correct URL from DE (I tried two versions)
  3. Created triggered email and picked one created in step 2 to use in sends
  4. Tested sending email and version 1 worked but only when I send it manually from MC

Do with API after button is clicked:

  1. Get token from Marketing Cloud
  2. Create Data Extension record that includes DocumentName, Contact (customers email) and PublicUrl from SF
  3. Send triggered email (https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/messageDefinitionSends.html)

Data extension:
Data Extension Info

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'.

Best Answer

isolate - remove all personalization / ampscript etc. from the email, retest.

If the same plain email works from "within" SFMC but keeps failing from your call, the problem must be some conflicting information in the API call.

So: Have you checked whether your "From" and "To" data in the API call is valid?

  • Does your subscriber's email exist already inside the system with another subscriber key?

  • you can try using a new email + new subscriber key to be absolutely sure

  • Is your to-email address valid, i.e. can you receive other SFMC mails from this BU to it, or could list detective etc be a problem)?

  • Is the "from" address validated? Can you leave the whole section out:

"From" : { 
    "Name" : "Srdjan Milankov", 
    "Address" : "[email protected]" 
  }, 

and just reference in the triggered send definition? (assuming you are using this call):

https://{{et_subdomain}}.rest.marketingcloudapis.com/messaging/v1/messageDefinitionSends/key:<tsd_external_key>/send
Related Topic