0

I am aware that 'SubscriberKey' is not supported as a valid parameter while using Triggered send.

Is there any posibility of avoiding creation of duplicate contact? As all my current Contacts have the subscriberkey as 18digit contact-ID [ex: 003xxxxxxxxxxxxxxx]

And I don't want the triggered sends to create a duplicate contacts[2nd one as below] with same email address.

Email address           SubscriberKey
abc@example.com    003xxxxxxxxxxxxxxx
abc@example.com    abc@example.com

3 Answers 3

2

I would recommend using an external service via API or WSProxy instead of the Core functions to get around this if it is a limitation. Zuzanna has written a great article about this here.

Here is a great example of the REST API endpoint and payload to send including the subscriberkey:

POST /messaging/v1/messageDefinitionSends/key:{{messagekey}}/send
Host: {{subDomain}}.rest.marketingcloudapis.com
Content-Type: application/json
Authorization: Bearer {{authToken}}

{
    "From": {
        "Address": "me@salesforce.com",
        "Name": "Learning Account"
    },
    "To": {
        "Address": "help@example.com",
        "SubscriberKey": "12356",
        "ContactAttributes": {
            "SubscriberAttributes": {
                "First_Name": "Aaron",
                "Cart_Total": "27.84",
                "Order_Number": 123456,
                "Purchase_Date": "2019-07-11T18:32:15Z",
                "Sub_Total": "30.01",
                "Tax": "2.17"
            }
        }
    }
}

This is a good resource for information on SFMC REST API calls outside official docs.

Below is a sample WSProxy call lifted from that article by Zuzanna:

<script runat="server">
Platform.Load("Core", "1")    
var prox = new Script.Util.WSProxy();
var tsExKey = 'External Key'; //pass Triggered Send External Key
var EmailAddress = 'example@example.com'; //pass Email Address
var SubscriberKey = 'example@example.com'; //pass Subscriber Key
var tsDef = {
    TriggeredSendDefinition: {
        CustomerKey: tsExKey
    },
    Subscribers: [{
        EmailAddress: EmailAddress,
        SubscriberKey: SubscriberKey
    }]
};
var res = prox.createItem('TriggeredSend', tsDef);  
Write(Stringify(res));
</script>

BUT I do believe you can add in subscriberkey to the TriggeredSend.Send core function. Here is a great article written by Ivan about it.

Here is a snippet from the article showing how it is done: (it is assuming that the vars are defined in AMPscript. You can adjust this to instead call your SSJS vars if you want.)

<script runat="server">

    Platform.Load("core","1.1");

    var data = {
        attributes : {
            FirstName: Platform.Variable.GetValue("@FirstName"),
            Language: Platform.Variable.GetValue("@Language")
        },
        subscriber : {
            EmailAddress: Platform.Variable.GetValue("@EmailAddress"),
            SubscriberKey: Platform.Variable.GetValue("@SubscriberKey")
        }
    }

    var TSD = TriggeredSend.Init(Platform.Variable.GetValue("@TriggeredSendExternalKey"));
    var Status = TSD.Send(data.subscriber,data.attributes);

</script>
3
  • @ GortoningtonThanks for sharing above solutions while working withing from SFMC. .....Bug I am currently firing the triggers from an EXTERNAL web application server via REST api... So how would I proceed. Jun 5, 2020 at 5:23
  • 1
    @VishalKumarCV - That actually is even easier. I am going to update my answer with the REST API information. Please make sure to specify in your question next time so we can make sure to include the correct information. Based on your reference to the core library function in your question, I assumed it was internal to SFMC. Jun 5, 2020 at 13:02
  • 1
    Thank you so much @Gortonington ... Also many thanks for sharing the link of such a useful collection of REST APIs... Apologies and I'll make sure to include complete information in my future queries thank you. Jun 5, 2020 at 14:04
1

You could use the API in SSJS. Get a token, define the variables (one of them being subscriberKey) and run this. You can get rid of the Attributes in case you don't need them.

<script type="javascript" runat="server">
try {
          var url = soapEndpoint + 'Service.asmx';
          var contentType = 'text/xml; charset=UTF-8';
          var headerNames = ["SOAPAction"];
          var headerValues = ["Create"];
          var payload = "";
          payload += '<?xml version="1.0" encoding="UTF-8"?>';
          payload += '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">';
          payload += '<s:Header>';
          payload += '    <fueloauth>' + access_token + '</fueloauth>';
          payload += '</s:Header>';
          payload += '<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">';
          payload += '    <CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">';
          payload += '        <Objects xsi:type="TriggeredSend">';
          payload += '           <Client>';
          payload += '              <ID>' + account_id + '</ID>';
          payload += '         </Client>';
          payload += '      <PartnerKey xsi:nil="true"/>';
          payload += '          <ObjectID xsi:nil="true"/>';
          payload += '               <TriggeredSendDefinition>';
          payload += '                    <PartnerKey xsi:nil="true"/>';
          payload += '                   <ObjectID xsi:nil="true"/>';
          payload += '                  <CustomerKey>' + triggeredSendCustomerKey + '</CustomerKey>';
          payload += '             </TriggeredSendDefinition>';
          payload += '             <Subscribers>';
          payload += '                 <PartnerKey xsi:nil="true"/>';
          payload += '                 <ObjectID xsi:nil="true"/>';
          payload += '                 <EmailAddress>' + email + '</EmailAddress>';
          payload += '               <SubscriberKey>' + subscriberKey + '</SubscriberKey>'; 
          payload += '               <Attributes>';
          payload += '                  <Name>permissionType</Name>';
          payload += '                  <Value>' + permissionType + '</Value>';
          payload += '               </Attributes>';
          payload += '               <Attributes>';
          payload += '                  <Name>source</Name>';
          payload += '                  <Value>' + source + '</Value>';
          payload += '               </Attributes>';
          payload += '            </Subscribers>';
          payload += '        </Objects>';
          payload += '    </CreateRequest>';
          payload += '</s:Body>';
          payload += '</s:Envelope>';
          var result = HTTP.Post(url,contentType,payload,headerNames,headerValues);
          var statusCode = result["StatusCode"];
          var tsResponse = result["Response"][0];
          tsResponse = Stringify(tsResponse).replace(/[\n\r]/g, '');
          Variable.SetValue("@statusmessage","doiInitiated");
        }
        catch (err)  {
          // error
              Write(Stringify(err));
        }

</script>
1
  • @ Jonas LambertyThanks for sharing above solutions while working withing from SFMC. .....Bug I am currently firing the triggers from an EXTERNAL web application server via REST api... Can you share the above solution in REST API format. Jun 5, 2020 at 5:25
1

The best part about the Triggered Send is that you have an option to exclude those subscribers. You can use this below approach if you are just sending one email for a contact and not to send another email for contact with same email address.

Approach: On top of your triggered email you can just add an ampscript to add a record in data extension.

%%[
// Add attribute values of your triggered send data extension should be here
    InsertDE('SomeDE','Email',@Email, 'LastName',LastName, 'CreatedDate',NOW())
]%%

In your triggered send you just use the below exclusion scripts to avoid the data with same email address

ADD(ROWCOUNT(LOOKUPROWS("Exclusion DE","email",AttributeValue("email")))) > 0

Let me know if this helps.

2
  • Thanks Naveen, but my issue is to have the duplicates NOT created while triggering from an External application via REST API Jun 5, 2020 at 5:26
  • You can still use the above approach for the REST API as well. Imagine that you are sending an email for first time then the email will go out. Using the ampscript on top of your email will add a record in a data extension. Next time if the same email address with a different contact ID sends to triggered sends then exclusion script will take care of your duplicates. Let me know if you need anything.
    – Naveen VM
    Jun 5, 2020 at 5:35

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.