1

EDIT

The issue was that I have SUBSCRIBER_KEY functionality turned on for my account, so I need to set the SendableSubscriberField to 'Subscriber Key' or the call will fail.


I have been able to utilize similar SSJS code previously and have mimicked some similar questions from SFSE, but everything I try, winds up with me receiving a 405 Error Method Not Allowed.

If anyone can help me find what I am missing/forgetting to do/doing wrong in the below snippet, it would be GREATLY appreciated.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title></title>
   </head>
<body>
<script runat="server"> 

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

    var user = 'User';
    var pass = 'Pass';
    var payload = '';
    var endpoint = 'https://webservice.exacttarget.com/Service.asmx'
    var result;

    // Create SOAP Call

    payload += '<?xml version="1.0" encoding="UTF-8"?>';
    payload += '<Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
    payload += '        <Header>';
    payload += '            <Action mustUnderstand="1">Create</Action>';
    payload += '            <Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">';
    payload += '                <UsernameToken>';
    payload += '                    <Username>' + user + '</Username>';
    payload += '                    <Password>' + pass + '</Password>';
    payload += '                </UsernameToken>';
    payload += '            </Security>';
    payload += '         </Header>';
    payload += '        <Body>';
    payload += '            <CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI" >';
    payload += '              <Options></Options>';
    payload += '              <Objects xmlns:ns1="http://exacttarget.com/wsdl/partnerAPI" xsi:type="ns1:DataExtension">';
    payload += '                <CustomerKey>CustomerKey</CustomerKey>';
    payload += '                <Name>CustomerKey</Name>';
    payload += '                <IsSendable>true</IsSendable>/';
    payload += '                <SendableDataExtensionField>';
    payload += '                  <CustomerKey>EmailAddress_Key</CustomerKey>';
    payload += '                  <Name>EmailAddress</Name>';
    payload += '                  <FieldType>EmailAddress</FieldType>';
    payload += '                </SendableDataExtensionField>';
    payload += '                <SendableSubscriberField>';
    payload += '                  <Name>Email Address</Name>';
    payload += '                  <Value></Value>';
    payload += '                </SendableSubscriberField>';
    payload += '                <Fields>';
    payload += '                    <Field>';
    payload += '                        <CustomerKey>EmailAddress_Key</CustomerKey>';
    payload += '                        <Name>EmailAddress</Name>';
    payload += '                        <FieldType>EmailAddress</FieldType>';
    payload += '                    </Field>';
    payload += '                    <Field>';
    payload += '                        <CustomerKey>ChannelUser_Key</CustomerKey>';
    payload += '                        <Name>ChannelUser</Name>';
    payload += '                        <FieldType>Text</FieldType>';
    payload += '                    </Field>';
    payload += '                </Fields> ';
    payload += '              </Objects> ';  
    payload += '            </CreateRequest>';
    payload += '       </Body>';
    payload += '</Envelope>';

    try {
        result = HTTP.Post(endpoint, "text/xml", payload, ["SOAPAction"], ["Create"]);
    } catch (e) {
        Write(Stringify(e));
    }

    Write(Stringify(result));

</script>
</body>
</html>
5
  • Is there any reason you have to use the SOAP call? Can't you use the out of box SSJS function?
    – 0xsegfault
    Sep 25, 2017 at 18:43
  • 1
    Have to create across different MIDs (not related) and out of the box SSJS will only work on the MID it is built on. Sep 25, 2017 at 18:44
  • Do you have the right endpoint URL for the stack the MID(s) are one? Also, you might try using the SJS library 1.1.1. (Just guesses at this point) :) Sep 26, 2017 at 2:31
  • I do have the right stackendpoint, I will try using 1.1.1. Guesses are definitely appreciated! I am at my wits end on this one. Sep 26, 2017 at 2:33
  • No such luck, changing the SSJS library did not help. :( Sep 26, 2017 at 12:45

2 Answers 2

2

I'm not sure why you would want to make an HTTP.POST call to the SOAP API to achieve this.

If you use the platform API functions available in SSJS (or AMPscript), that will take care of authentication and also resolve the correct Web Service endpoint.

Here's how you would create a Sendable DE using platform API functions in SSJS:

<script runat="server">
Platform.Load("Core","1");

var de = Platform.Function.CreateObject("DataExtension");

Platform.Function.SetObjectProperty(de, "Name", "My Sendable DE"); 
Platform.Function.SetObjectProperty(de, "Description", "A DE created via SSJS"); 
Platform.Function.SetObjectProperty(de, "IsSendable", "true"); 
Platform.Function.SetObjectProperty(de, "IsTestable", "false"); 

var deFields = Platform.Function.CreateObject("DataExtensionField");
Platform.Function.SetObjectProperty(deFields, "FieldType", "Text"); 
Platform.Function.SetObjectProperty(deFields, "Name", "Id"); 
Platform.Function.SetObjectProperty(deFields, "MaxLength", 18); 
Platform.Function.SetObjectProperty(deFields, "IsPrimaryKey", "true"); 
Platform.Function.SetObjectProperty(deFields, "IsNillable", "false"); 
Platform.Function.SetObjectProperty(deFields, "IsRequired", "true"); 
Platform.Function.AddObjectArrayItem(de, "Fields", deFields);

Platform.Function.SetObjectProperty(de,"SendableDataExtensionField",deFields)

var deFields = Platform.Function.CreateObject("DataExtensionField");
Platform.Function.SetObjectProperty(deFields, "FieldType", "Text"); 
Platform.Function.SetObjectProperty(deFields, "Name", "Name"); 
Platform.Function.SetObjectProperty(deFields, "MaxLength", 50); 
Platform.Function.AddObjectArrayItem(de, "Fields", deFields);

var deFields = Platform.Function.CreateObject("DataExtensionField");
Platform.Function.SetObjectProperty(deFields, "FieldType", "EmailAddress"); 
Platform.Function.SetObjectProperty(deFields, "Name", "Email Address"); 
Platform.Function.SetObjectProperty(deFields, "IsNillable", "false"); 
Platform.Function.SetObjectProperty(deFields, "IsRequired", "true"); 
Platform.Function.AddObjectArrayItem(de, "Fields", deFields);

var subscriberAttr = Platform.Function.CreateObject("Attribute");
Platform.Function.SetObjectProperty(subscriberAttr, "Name", "Subscriber Key");
Platform.Function.SetObjectProperty(subscriberAttr, "Value", "Id");
Platform.Function.SetObjectProperty(de, "SendableSubscriberField", subscriberAttr);

var statusAndRequestID = [0,0];

var statMsg = Platform.Function.InvokeCreate(de, StatusAndRequestID, null);
Platform.Response.Write('status message: ' + statMsg);
</script>

In the above example, I've created the Subscriber relationship based on Subscriber Key = the Id field in my DE. However you could change this relationship to be based on email address by changing the following lines:

Platform.Function.SetObjectProperty(subscriberAttr, "Name", "Subscriber Key");
Platform.Function.SetObjectProperty(subscriberAttr, "Value", "Id");

To:

Platform.Function.SetObjectProperty(subscriberAttr, "Name", "Email Address");
Platform.Function.SetObjectProperty(subscriberAttr, "Value", "Email Address");
1
  • 1
    Thanks for the answer @EliotHarper, utilizing the platform API is always a great capability, but the purpose of POSTing was to make calls from one BU into others inside an E1 environment all within 1 script activity. Jul 11, 2018 at 22:00
1

I got this working by making few changes. the endpoint looks wrong to me.

MY instance is on s10 stack. so I have used the below endpoint and it works.

https://webservice.s10.exacttarget.com/Service.asmx

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script runat="server">
Platform.Load("core", "1");    
var payload = '<?xml version="1.0" encoding="UTF-8"?> <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">  <s:Header>     <a:Action 
s:mustUnderstand="1">Create</a:Action>     
<a:MessageID>urn:uuid:7e0cca04-57bd-4481-864c-
6ea8039d2ea0</a:MessageID>     <a:ReplyTo>    <a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>     </a:ReplyTo>     <a:To s:mustUnderstand="1">https://webservice.s10.exacttarget.com/Service.asmx</a:To>      <Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">                    <UsernameToken>                        <Username>*****</Username>                        <Password>****</Password>                    </UsernameToken>                </Security>  </s:Header> <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">     <CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">        <Options/>        <Objects xsi:type="DataExtension">           <PartnerKey xsi:nil="true"/>           <ObjectID xsi:nil="true"/>           <Name>Sam_DE</Name>           <IsSendable>false</IsSendable>           <Fields>              <Field>                 <Name>EmailAddress</Name>                 <FieldType>EmailAddress</FieldType>                 <IsPrimaryKey>true</IsPrimaryKey>                 <IsRequired>true</IsRequired>              </Field>              <Field>                 <Name>SubscriberKey</Name>                 <FieldType>Text</FieldType>                 <IsRequired>false</IsRequired>              </Field>              <Field>                 <Name>Date</Name>                 <FieldType>Date</FieldType>                 <DefaultValue>getdate()</DefaultValue>                 <IsRequired>true</IsRequired>              </Field>              <Field>                 <Name>Average_Order_Value</Name>                 <FieldType>Decimal</FieldType>                 <IsRequired>true</IsRequired>                 <Precision>10</Precision>                 <Scale>2</Scale>              </Field>              <Field>                 <Name>Is_Proofing_Customer</Name>                 <FieldType>Boolean</FieldType>                 <DefaultValue>true</DefaultValue>                 <IsRequired>true</IsRequired>              </Field>              <Field>                 <Name>Number_of_Clusters</Name>                 <FieldType>Number</FieldType>                 <IsRequired>false</IsRequired>              </Field>              <Field>                 <Name>Telephone</Name>                 <FieldType>Phone</FieldType>                 <IsRequired>false</IsRequired>              </Field>              <Field>                 <Name>Locale</Name>                 <FieldType>Locale</FieldType>                 <IsRequired>false</IsRequired>              </Field>           </Fields>           <CustomerKey>SamDE01</CustomerKey>        </Objects>     </CreateRequest> </s:Body></s:Envelope>';
var endpoint = 'https://webservice.s10.exacttarget.com/Service.asmx';
var result;

// Create SOAP Call


try {
  //Write(payload);
    result = HTTP.Post(endpoint, "text/xml", payload, ["SOAPAction"], ["Create"]);
} catch (e) {
    Write(Stringify(e));
}

Write(Stringify(result));

</script>
</body>
</html>
2
  • Hello Praveen, thank you for catching that. I did copy the wrong link in my question, but the issue was actually that I had Subscriber_Key turned on for my account and I could not have the SendableSubscriberField be Email Address. Sep 26, 2017 at 14:56
  • 1
    oh cool. Glad you figured the issue @Gortonington Sep 27, 2017 at 2:03

You must log in to answer this question.

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