2

I am using Fuel-Node-Soap and Fuel-Node-Auth to create a command line app that allows us to create and update emails as well as email folders from out dev environment.

I have successfully been able to create new emails and retrieve emails in a specified folder and update that email. However, I can not figure out how to create new folders to save an email in.

Creating an email - this works as expected:

// Create filter object
function filterObj (leftOp, op, rightOp) {
var filter = {
    leftOperand: leftOp,
    operator: op,
    rightOperand: rightOp
};
return filter;
} 

// Create email
program
.command('create <filePath> <emailName> <emailSubject>')
.option('-f, --folder <name>', 'Retrieve existing folder by name')
.description('Create new email in ExactTarget')
.action(function(filePath, emailName, emailSubject, options) {
    var file = fs.readFileSync(filePath, "utf8");
    if (file) {
        if (options.folder) {
            var ParentFolderFilter = filterObj('Name', 'equals', options.folder);
            SoapClient.retrieve(
                "DataFolder", ["ID"],
                ParentFolderFilter,
                function(err,
                    response) {
                    if (err) {
                        console.log(err);
                    } else {
                        // Parent folder ID
                        var pID = response.body.Results[0].ID,
                            CreateEmailObj = {
                                Name: emailName,
                                Subject: emailSubject,
                                EmailType: 'HTML',
                                IsHTMLPaste: true,
                                HTMLBody: file,
                                CategoryID: pID
                            };
                        SoapClient
                            .create(
                                'Email',
                                CreateEmailObj,
                                function(err, res) {
                                    if (err) {
                                        console.log(err);
                                        process.exit(1);
                                    } else {
                                        console.log("Email '%s' created", emailName);
                                        process.exit(0);
                                    }
                                });
                    }
                });
        } else {
            var CreateEmailObj = {
                Name: emailName,
                Subject: emailSubject,
                EmailType: 'HTML',
                IsHTMLPaste: true,
                HTMLBody: file,
            };
            SoapClient.create(
                'Email',
                CreateEmailObj,
                function(err,
                    res) {
                    if (err) {
                        console.log(err);
                        process.exit(1);
                    } else {
                        console.log("Email '%s' created", emailName);
                        process.exit(0);
                    }
                });
        }
    } else {
        console.log('File does not exist');
        process.exit(1);
    }
});

Update existing email in specific folder - this works as expected:

// Update email
program
.command('update <emailName> <folderName>')
.description('Update existing email in ExactTarget')
.option('-s, --subject_update <subject>', 'Update subject line')
.option('-c, --code_update <filePath>', 'Update code')
.action(function(emailName, folderName, options) {
    var emailFilter = filterObj('Name', 'equals', emailName),
        folderFilter = filterObj('Name', 'equals', folderName);
    // Get parent folder ID
    SoapClient.retrieve(
        "DataFolder", ["ID"],
        folderFilter,
        function(err, response) {
            if (err) {
                console.log(err);
                process.exit(1);
            } else {
                // Parent folder ID
                var pID = response.body.Results[0].ID;
                // Get existing email ID
                SoapClient.retrieve(
                    'Email', ["ID"],
                    emailFilter,
                    function(err, response) {
                        if (err) {
                            console.log(err);
                            process.exit(1);
                        } else {
                            var UpdateEmailObj = {
                                Name: emailName,
                                ID: response.body.Results[0].ID,
                                CategoryID: pID
                            };
                            // Update subject line
                            if (options.subject_update) {
                                UpdateEmailObj.Subject = options.subject_update;
                            }
                            // Update HTML
                            if (options.code_update) {
                                var file = fs.readFileSync(options.code_update, "utf8");
                                if (file) {
                                    UpdateEmailObj.HTMLBody = file;
                                } else {
                                    console.log("File does not exist");
                                    process.exit(1);
                                }
                            }
                            // Update email
                            SoapClient.update(
                                'Email',
                                UpdateEmailObj,
                                function(err, response) {
                                    if (err) {
                                        console.log(err);
                                        process.exit(1);
                                    } else {
                                        console.log("Email '%s' updated", emailName);
                                        process.exit(0);
                                    }
                                });
                        }
                    });
            }
        });
});

Creating a new folder - does not work:

// Create new folder
program
.command('newfolder <folderName>')
.description('Create a new country folder')
.action(function(folderName) {
    var topFolder = "Rapid Launch",
        filter = filterObj('Name', 'equals', topFolder);
    SoapClient.retrieve(
        'DataFolder', ["ID", "Description"],
        filter,
        function(err,
            response) {
            if (err) {
                console.log(err);
                process.exit(1);
            } else {
                var pID = response.body.Results[0].ID,
                    CreateFolderObj = {
                        Name: folderName,
                        ContentType: "email",
                        IsActive: true,
                        IsEditable: true,
                        ParentFolder: {
                            ID: pID
                            Name: topFolder
                        }
                    };
                SoapClient.create(
                    'DataFolder',
                    CreateFolderObj,
                    function(err, res) {
                        if (err) {
                            console.log(err);
                            process.exit(1);
                        } else {
                            console.log("Folder '%s created", folderName);
                            process.exit(0);
                        }
                    });
            }
        });
});

When running the command to create a new folder, i get the following error:

{ [Error: Soap Error]
  requestId: '121954b0-cbd4-4a4b-ab01-50c59a392d86',
  results: 
   [ { StatusCode: 'Error',
       StatusMessage: 'An unknown error occured while processing. Error ID: 1890429578',
       OrdinalID: '0',
       ErrorCode: '2',
       NewID: '0' } ],
errorPropagatedFrom: 'CreateResponse' }

According to the ExactTarget documentation, error code 2 is an unexpected error:

  • Type: System - General Exception
  • Message
    • Exception occurred during [{Operation}] ErrorID: {ErrorID}
  • Resolution
    • Log error information
    • Contact ExactTarget support
  • Note
    • This error code can be on a SOAP fault during authentication (login has an unexpected exception)

Any help would be greatly appreciated

1
  • ErrorCode 2 is a general error. Best course would be to log the SOAP envelope and then submit a case to [email protected]
    – mobo
    Jan 9, 2015 at 1:27

2 Answers 2

1

Thank you for using the fuel-soap library. It looks like you have forgotten a comma in your ParentFolder object. This could be a typo. You should only need to provide the ParentFolder.ID. I am currently using the library to create folder structures. I have provided a working snippet.

client.create(
    "DataFolder",
    {
        CustomerKey: "TEST_FOLDER_20150129",
        Name: "TEST_FOLDER_20150129",
        Description: "Test Folder using fuel-soap",
        ContentType: "email",
        IsActive: true,
        IsEditable: true,
        AllowChildren: true,
        ParentFolder: {
            ID: "2149"
        }
    },
    function(err, response) {
        if ( err ) {
            throw err;
        }
        console.log(response.body);
    }
);

Also, make sure the ContentType of the folder you are creating matches the ContentType of the ParentFolder.

0

Main thing is to make sure you include the "description" property when creating a DataFolder else you will get that "unknown error" message. The field is (perhaps erroneously) required but unlike other required data elements for a DataFolder does not provide an informative error message when it's missing.

You must log in to answer this question.

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