2

I'm looking to create an Email Send Definition via WSProxy. I am trying to mirror the SOAP Envelope for my proxy script.

I am getting an error when trying to create it; Error Code: 2...

<script runat='server'>
Platform.Load("core", "1.1.1");

//Get External/CustomerKey of ObjectID based on DE Name
function getDEobjectID(deName){
var prox = new Script.Util.WSProxy();
var cols = ["ObjectID"];
var filter = {
    Property: "Name",
    SimpleOperator: "equals",
    Value: deName
};  
  
var result = prox.retrieve("DataExtension", cols, filter);
var objectID = result.Results[0].ObjectID;  

Write("ObjectID: " + objectID + "<br><br>");

return objectID;
};


var deName = "DEName";
var objectID = getDEobjectID(deName);


var prox = new Script.Util.WSProxy();
  
var esd = {
    "Name": "SOAP_ESD_test1",
    "SendDefinitionList": [{
        "CustomObjectID": objectID,
        "DataSourceTypeID": "CustomObject"
    }],
    "Email": {
        "ID": 6499
    },
    "SendClassification": {
        "CustomerKey": "Default Commercial"
    }
};


try {

    var res = prox.createItem("EmailSendDefinition", esd);
    Write('Response: ' + Stringify(res) + '<br><br>');

} catch (e) {
    Write(Stringify(e));
}

</script>

1 Answer 1

2

I think the problem is that you're trying to pass external keys in SendDefinitionList, while you should be passing Object IDs.

I managed to get this to work in a simplified version with just a Data Extension, an Email and the Default Commercial send classification:

Platform.Load("core", "1.1.1");
var prox = new Script.Util.WSProxy();

var esd = {
    "Name": "ESD_test",
    "SendDefinitionList": [{
        "CustomObjectID": "e1c9a5fa-4eb1-ea11-80fd-1402ec819df9",
        "DataSourceTypeID": "CustomObject"
    }],
    "Email": {
        "ID": 21510
    },
    "SendClassification": {
        "CustomerKey": "Default Commercial"
    }
};


try {
    var res = prox.createItem("EmailSendDefinition", esd);
    Write('Response: ' + Stringify(res) + '<br><br>');

} catch (e) {
    Write(Stringify(e));
}

Here is the result:

enter image description here

6
  • PS. For when you're testing, I highly recommend Marcus' chrome plugin to get the DE Object IDs without having to add more code :-) chrome.google.com/webstore/detail/salesforce-marketing-clou/…
    – zuzannamj
    Commented Aug 7, 2020 at 11:03
  • I have a function that grabs DE data so I modified it to grab the ObjectID. Still getting errors through... I've edited my code above to show the new script. I've tried hard coding the objectID as well, same result. - Made sure the DE I'm using is sendable - SendClassification exists - EmailID exists/is correct I also have full admin permissions for this instance as well... Commented Aug 7, 2020 at 12:35
  • And what does the error say?
    – zuzannamj
    Commented Aug 7, 2020 at 12:42
  • 42116 ESD_Null Value Commented Aug 7, 2020 at 12:45
  • 1
    Got it! So apparently in the Sandbox environment I'm working in, the "Default Commercial" classification is not verified... so it was coming through as null! Changed that and it worked! Commented Aug 7, 2020 at 12:53

You must log in to answer this question.

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