0

I want to create a Triggered Send Definition using "createItem" method under WSProxy . However i am unable to find any example on the same . I am fairly new to using APIs and need to refer to some working example in order to understand the flow . Can someone please point me in right direction?

2
  • Are you wanting to send a triggered send email or just create a definition? Feb 13, 2020 at 14:30
  • @AdamSpriggs - Yes, I want to create a Triggered Send definition Feb 13, 2020 at 17:42

1 Answer 1

3

It's nicely explained in Send a triggered email using WSProxy article from sfmarketing.cloud blog.

Triggered Send object:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <Header>
    <fueloauth>YOUR_ACCESS_TOKEN</fueloauth>
 </Header>
 <Body>
   <CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
    <Objects xsi:type="TriggeredSend">
      <PartnerKey xsi:nil="true"/>
      <ObjectID xsi:nil="true"/>
      <TriggeredSendDefinition>
       <PartnerKey xsi:nil="true"/>
       <ObjectID xsi:nil="true"/>
       <CustomerKey>Definition_Key</CustomerKey>
      </TriggeredSendDefinition>
      <Subscribers>
       <PartnerKey xsi:nil="true"/>
       <ObjectID xsi:nil="true"/>
       <EmailAddress>[email protected]</EmailAddress>
       <SubscriberKey>[email protected]</SubscriberKey>
       <Attributes>
         <Name>firstname</Name>
         <Value>John</Value>
       </Attributes>
      </Subscribers>
    </Objects>
   </CreateRequest>
 </Body>
</Envelope>

Script using craeteItem function:

To create a new TriggeredSend, we will use the createItem WSProxy function, which has three parameters:

  • The first parameter is the object type to perform the action on – here, we will use previously mentioned TriggeredSend object
  • The second parameter is a JavaScript object which represents the fields and values to set on the object when created – in below example, we will call it tsDef and use it to define the CustomerKey, Subscribers and optionally, their Attributes
  • The third parameter is optional and includes any properties to be set using the SOAP CreateOptions object
<script runat="server">       
var prox = new Script.Util.WSProxy();
var tsExKey = ''; //provide Triggered Send External Key
var EmailAddress = ''; //pass Email Address
var SubscriberKey = ''; //pass Subscriber Key
var firstName = ''; //pass First Name
var lastName = ''; //pass Last Name
var tsDef = {
    TriggeredSendDefinition: {
        CustomerKey: tsExKey
    },
    Subscribers: [{
        EmailAddress: EmailAddress,
        SubscriberKey: SubscriberKey,
        Attributes: [{
            Name: 'firstName',
            Value: firstName
        }]
    }]
};
var res = prox.createItem('TriggeredSend', tsDef);      
</script>
1
  • Hi @przemyslaw, Thanks for your input. However this example does not explain how to "Create" a Triggered Send Definition using WsProxy. My requirement is to create a TSD from a cloud page.Can you give me some pointers on that? Feb 13, 2020 at 17:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .