2

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" : "test@testemail.com" 
  }, 
  "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" : "test@testemail.com" 
  }, 
  "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'.

2
  • One thing -- AttributeValue("_DocumentName") should be AttributeValue("DocumentName"). in your email. Needs to match the DE column and the payload attribute name. Feb 7 at 13:07
  • Thank you @AdamSpriggs, I changed that but result is still the same. Sometimes MC don't even register that triggered email is in queue, I receive response that it is but in triggered sends I can see that 0 is in queue.
    – smilankov
    Feb 7 at 15:08

1 Answer 1

0

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" : "test@testemail.com" 
  }, 

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
5
  • I tried to send email without AMPScript, but still after queue, status is 'Errored', and when I use same email and test it from MC it works. Email address I am using in 'From' part when making API call is used to send various emails from MC directly and there were no issues. I can leave whole 'From' section out, but while setting up triggered email I checked override sender profile so I don't know does that matters. Thank you for your help.
    – smilankov
    Feb 8 at 11:31
  • What you specify in "From" is not a sender profile. A sender profile contains more than just from name and email - You are making a custom setting, and I believe that this is treated with priority. So, if your custom input is invalid, it could plausibly kill the sendout. So, try leaving the whole from section out. Feb 8 at 11:40
  • Wow, when I removed 'From', it actually works, even the emails that include AMPScript. :D Thank you very much Jonas! If I have any more issues I will open new thread, so we may consider this solved.
    – smilankov
    Feb 8 at 15:16
  • Nice. Not gonna say I told you so - but I told you so :D The thing is, the headline is now a bit misleading. this has nothing to do with public file URLs, Sales Cloud etc, but it's a simple "triggered send failed" scenario. maybe that's worth editing for future searches. Feb 8 at 15:24
  • Added triggered send failed in headline for future searches, but didn't deleted rest of the headline, maybe someone will need similar functionality and this thread can help him. Thank you again and have a nice day! :)
    – smilankov
    Feb 9 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.