0

I've managed to get an ImportDefinition created with the destination object being a list in postman, but I'm struggling a bit with wsproxy, I'm getting a 500 server error. My contentJson is read ok, and my listID is returned ok.

 <script runat="server">
    Platform.Load("core", "1.1.1");
    
    var api = new Script.Util.WSProxy();

    try {

  var soapObjName = "ImportDefinition";
  var filter = 
        {
          Property: "ListName",
          SimpleOperator: "equals",
          Value: "All Subscribers"
        };
  var req = api.retrieve("List", ["ID"], filter);

//set the listID variable with the results
  var listID = req.Results[0].ID;

  var contentJSON = 
   [ {
    CustomerKey: "wsProxyImportDef",
    Name: "wsProxyImportDefName",
    Description: "wsProxyImportDefDesc",
    AllowErrors: true,
    DestinationObject: [{
      DestinationType: "List",
      ID: listID
      }],
    FieldMappingType: "InferFromColumnHeadings",
    FieldSpec: "Import2M2L.csv",
    FileType: "CSV",
    Notification: [{
      "ResponseType": "email",
      "ResponseAddress": "developer@xyz"
      }],
    UpdateType: "Add and Update"
    }
    ];

   
    var createImportDefinition = createGeneric(soapObjName, contentJSON, '')
    Write(Stringify(createImportDefinition))
  
  
    function createGeneric(soapObjName, contentJSON, mid) {
      try {
        if (mid) {
          api.resetClientIds();
          //reset previous settings
          //Set ClientID
          api.setClientId({
            ID: mid
          });
        }
  
        var batch = isArray(contentJSON);
  
        Write(Stringify(batch))
  
        if (batch) {
          var res = api.createBatch(soapObjName, contentJSON);
        } else {
          var res = api.createItem(soapObjName, contentJSON);
        }
  
  
  
        function isArray(arg) {
          return Object.prototype.toString.call(arg) === '[object Array]';
        };
  
        return res;
      } catch (err) {
        Write(Stringify(err))
      }
    }
  
  </script>

Thanks to Gortonington and Jason Henshaw for the ws proxy create framework

2
  • I am not sure if this helps... I noticed 2 things.... 1) There are two TRY, so please add one more CATCH block... 2) I see this error now, I assume CreateBatch is failing because of this error... System.ArgumentException: Object of type 'System.Collections.ArrayList' cannot be converted to type 'ExactTarget.Integration.WSDL.APIObject'. - from mscorlib Commented Oct 6, 2022 at 13:13
  • Thanks for the heads up on the try catch. I removed it, and can see the same error you did. I then added another catch block after the var contentJSON and get this error false{"message":"Item properties are not valid.","description":"ExactTarget.OMM.InvalidFunctionParameterException: Item properties are not valid.\r\n Error Code: OMM_FUNC_CONTEXT_ERR\r\n - from Jint\r\n\r\n"}nul but I don't think the issue is with the description field Commented Oct 6, 2022 at 13:46

1 Answer 1

1

Here's a snippet that works:

<script runat="server" language="JavaScript">

Platform.Load("Core","1");
var prox = new Script.Util.WSProxy();
var importName = "DataExtension1ImportDefinition";
var targetDEKey = "DataExtension1";
var result = {};

try {

       var importDefinition = {

              "Name": importName,
              "CustomerKey": importName,
              "Description": importName,
              "AllowErrors": "true",
              "DestinationObject": {
                     "__Type__": "DataExtension",
                     "CustomerKey": targetDEKey
              },
              "FieldMappingType": "InferFromColumnHeadings",
              "FileSpec": "DataExtension1.csv",
              "FileType": "CSV",
              "Notification": {
                     "ResponseType": "email",
                     "ResponseAddress": "[email protected]"
               },
              "UpdateType": "AddAndUpdate",
              "RetrieveFileTransferLocation": {
                     "CustomerKey": "ExactTarget Enhanced FTP - Import"
              }
       };

       result = prox.createItem("ImportDefinition", importDefinition);

} catch (e) {

       Write("<br>e: " + Stringify(e))

}

Write("<br>result: " + Stringify(result))

</script>

Response/result:

{
    "Status": "OK",
    "RequestID": "dc70c30b-cc4f-4918-b6b0-920546779c10",
    "Results": [
        {
            "NewID": 0,
            "NewObjectID": "4163c08f-ef59-ed11-b847-48df37d1dadc",
            "PartnerKey": null,
            "Object": {
                "AllowErrors": true,
                "DestinationObject": {
                    "CustomerKey": "DataExtension1",
                    "Name": null,
                    "Description": null,
                    "IsSendable": false,
                    "IsTestable": false,
                    "SendableDataExtensionField": null,
                    "SendableSubscriberField": null,
                    "Template": null,
                    "DataRetentionPeriodLength": 0,
                    "DataRetentionPeriodUnitOfMeasure": 0,
                    "RowBasedRetention": false,
                    "ResetRetentionPeriodOnImport": false,
                    "DeleteAtEndOfRetentionPeriod": false,
                    "RetainUntil": null,
                    "Fields": null,
                    "DataRetentionPeriod": "Days",
                    "CategoryID": 0,
                    "Status": null,
                    "Client": null,
                    "PartnerKey": null,
                    "PartnerProperties": null,
                    "CreatedDate": "0001-01-01T00:00:00.000",
                    "ModifiedDate": null,
                    "ID": 0,
                    "ObjectID": null,
                    "Owner": null,
                    "CorrelationID": null,
                    "ObjectState": null,
                    "IsPlatformObject": false
                },
                "FieldMappingType": "InferFromColumnHeadings",
                "FieldMaps": null,
                "FileSpec": "DataExtension1.csv",
                "FileType": "CSV",
                "Notification": null,
                "RetrieveFileTransferLocation": {
                    "Client": null,
                    "PartnerKey": null,
                    "PartnerProperties": null,
                    "CreatedDate": "0001-01-01T00:00:00.000",
                    "ModifiedDate": null,
                    "ID": 0,
                    "ObjectID": null,
                    "CustomerKey": "ExactTarget Enhanced FTP - Import",
                    "Owner": null,
                    "CorrelationID": null,
                    "ObjectState": null,
                    "IsPlatformObject": false
                },
                "SubscriberImportType": "Email",
                "UpdateType": "AddAndUpdate",
                "MaxFileAge": 0,
                "MaxFileAgeScheduleOffset": 0,
                "MaxImportFrequency": 0,
                "Delimiter": null,
                "HeaderLines": 0,
                "AutoGenerateDestination": null,
                "ControlColumn": null,
                "ControlColumnDefaultAction": "AddAndUpdate",
                "ControlColumnActions": null,
                "EndOfLineRepresentation": null,
                "NullRepresentation": null,
                "StandardQuotedStrings": false,
                "Filter": null,
                "DateFormattingLocale": null,
                "DeleteFile": false,
                "SourceObject": null,
                "DestinationType": 0,
                "SubscriptionDefinitionId": null,
                "EncodingCodePage": 0,
                "SmsMemberSharedShortCodeId": null,
                "HasMultipleFiles": false,
                "InteractionObjectID": null,
                "Name": "DataExtension1ImportDefinition",
                "Description": "DataExtension1ImportDefinition",
                "Keyword": null,
                "Client": null,
                "PartnerKey": null,
                "PartnerProperties": null,
                "CreatedDate": "0001-01-01T00:00:00.000",
                "ModifiedDate": null,
                "ID": 0,
                "ObjectID": "4163c08f-ef59-ed11-b847-48df37d1dadc",
                "CustomerKey": "DataExtension1ImportDefinition",
                "Owner": null,
                "CorrelationID": null,
                "ObjectState": null,
                "IsPlatformObject": false
            },
            "CreateResults": null,
            "ParentPropertyName": null,
            "StatusCode": "OK",
            "StatusMessage": "ImportDefinition created.",
            "OrdinalID": 0,
            "ErrorCode": 0,
            "RequestID": null,
            "ConversationID": null,
            "OverallStatusCode": null,
            "RequestType": "Synchronous",
            "ResultType": null,
            "ResultDetailXML": null
        }
    ]
}

You must log in to answer this question.

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