1

I am developing an application to interact with our Marketing Cloud and I would like to be able to create custom Script Activities(containing SSJS API calls)through the API for each campaign so I can then add them to specific automations. Is this possible?

Also, if you know of a different way to do this please let me know.

  • To the best of my knowledge, Script Activities are not a valid object in the SOAP API and not accessible via REST either. What is the app use-case that you can't accomplish everything via SDK or w/ external API, but rely on script activities? – Jason Hanshaw Oct 26 '19 at 1:31
6

If you don't mind using undocumented REST endpoints, then yes! you can.

Create

POST /automation/v1/scripts
Host: {{subdomain}}.rest.marketingcloudapis.com
Authorization: Bearer {{authToken}}
Content-Type: application/json

        {
            "name": "RestAPIScript",
            "key": "RestAPIScript",
            "description": "",
            "script": "<script runat=\"server\">\n //This is javascript \n</script>",
            "categoryId": {{folderID}}
        }

Edit

PATCH /automation/v1/scripts/{{ssjsActivityId}}
Host: {{subDomain}}.rest.marketingcloudapis.com
Authorization: Bearer {{authToken}}
Content-Type: application/json

{
    "ssjsActivityId": "xxxxxx-xxxx-xxxx-xxxx-xxxxxx",
    "description": "",
    "script": "<script runat=\"server\">\n //This is javascript \n</script>",
    "categoryId": {{folderID}}
}

**note that you need to end this with the SSJS ObjectID and also include it in the payload.

Retrieve

GET /automation/v1/scripts 
Host: {{subdomain}}.rest.marketingcloudapis.com
Authorization: Bearer {{authToken}}
Content-Type: application/json

**Note that by leaving this endpoint as is you will retrieve all SSJS activities. You can also add a 'SSJSActivitiesID' (ObjectID) to the end and only retrieve a specific one as well. You also can use the $filter capabilities that are available inside of the Content Builder API retrieves.

Retrieve by Category

GET /automation/v1/scripts/category/{{folderID}} 
Host: {{subdomain}}.rest.marketingcloudapis.com
Authorization: Bearer {{authToken}}
Content-Type: application/json

This will retrieve all Script Activities inside of a specific folder.

Validation

POST /automation/v1/scripts/validate/ 
Host: {{subdomain}}.rest.marketingcloudapis.com
Authorization: Bearer {{authToken}}
Content-Type: application/json

{
    "script": "<script runat=\"server\">\n //This is javascript \n</script>"
}

**This will run your script against the SSJS validator that is inside SFMC to verify that what you are pushing into the UI is valid and functional before attempting creation/edit.

As stated above these are all undocumented and are use at your own risk. But, if you are willing to live with a little danger/risk, these can have a huge impact on your capabilities of interaction with SFMC via API. Just know that there can be bugs or 'quirks' with each and you will have no support from SFMC as they are not official endpoints and they even possibly can 'disappear' without notice.

Check out my blog post for some more info.

| improve this answer | |
  • Thanks again @Gortonington, this works perfectly! – Brett Oct 27 '19 at 22:05

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.