5

I'm trying to create a Script Activity through the API and I can't find any documentation for that SOAP Object. I tried pulling back an existing automation that contained a script activity but the Automation Activities can't be retrieved through the API or at least I haven't been able to find a way.

The basic use case is that I need to be able to delete a significant number of rows in a Data Extension based on a dynamic primary key value and using the SSJS DeleteData function.

Has anyone been able to create a script activity through the API?

0

The highly recommended, open source email360 library's (https://www.email360.io/salesforce-marketing-cloud-library) documentation lists and includes an internal method under its createScriptActivity() function. It leverages the endpoint under automation/v1/scripts with the following limitation:

Note: This is an internal only route, that currently is NOT supported. It should only be used in production environments with caution. The route has no ownership internally, and could stop working without notice.

Make of that constraint what you will (just make sure you take it seriously), but it looks like somebody indeed has done this.

documentation of the wrapper function: https://docs.email360.io/#sfmcapicreatescriptactivity

github link to source code: https://github.com/email360/ssjs-lib/blob/master/core/lib_sfmcapi.js

source code excerpt from above link:

        // ============================== SCRIPT ACTIVITY ==============================

        /** 
         * Create a Script Activity
         *
         * Note: This is an internal only route, that currently is NOT supported. It should only be used in production environments wiht caution. 
         * The route has no ownership internally, and could stop working without notice.
         *
         * @param {string} name             The name of the SSJS script
         * @param {string} script           The SSJS script to create
         * @param {number} [folderId]       The folder id the script will belong to. Default the default Scripts folderId from settings
         * @param {number} [description]    A brief description about the script
         *
         * @returns {object} Result set of the request.
         */
        this.createScriptActivity = function(name,script,folderId,description) {
            var categoryId = (folderId && Number.isInteger(folderId)) ? folderId : settings.fodlerId.Scripts,
                token = this.getToken(),
                config = {
                    url: setup.restBaseURI + "automation/v1/scripts",
                    contentType : "application/json",
                    header: {
                        Authorization: "Bearer " + token
                    },
                    payload : {
                        name: name,
                        key: Platform.Function.GUID().toUpperCase(),
                        description: description,
                        script: script,
                        categoryId: categoryId
                    }
                };

            var req = httpRequest('POST',config.url,config.contentType,config.payload,config.header);

            req.content.script = req.content.script.replace(/<script[\s\S]*?>/gi, '');
            req.content.script = req.content.script.replace(/<\/script>/gi, '');

            if( req.status == 201 ) {
                debug('(createScriptActivity)\n\tOK: Script Activity '+name+' has been created');
            } else {
                debug('(createScriptActivity)\n\tError: '+Platform.Function.Stringify(req));
            }
            return req;
        };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.