0

I have a script activity in Marketing Cloud that processes data from a Data Extension. The requirement is to run this script and save the results in a DE every day, not at a specific time/hour, but when something happens every day on an external system. The data that needs to be processed is in Marketing Cloud and the result should remain in Marketing Cloud, only the start of the job should be external.

I tried to find something on google but can't find what I need. Does anyone know how can I run the script from an external system? It's not important if it's REST API, SOAP API or anything else as long as it works.

Thank you!

2 Answers 2

3

My recommendation will be to place your SSJS in a JSON Code Resource. You can create one under Cloud Pages, where you choose Code Resource instead of Landing Page in the Add Content menu:

enter image description here

Here you can populate all the information about the resource:

enter image description here

And lastly choose JSON as Code Resource type:

enter image description here

{
<script runat="server">
Platform.Load("Core","1.1.1");
//check for API key
var apikey = Platform.Request.GetRequestHeader('x-api-key');
if (apikey == "5QZKGDHI70") {
try{
//Do your SSJS Functions Here

//Assign output from your function to *status* variable, and print it in JSON on success:
Write("\"success\": \"" + status + "\"");
} 
catch(error) {
//Print error message in JSON, if something fails
Write("\"error\": \"" + error + "\"");
}
} else {
Write("\"error\": \"Missing or incorrect API key\"");
}
</script>
}

Above SSJS will print the status of your function, error if your script fails, and do a basic security check, to see if the header holds the correct API key (so no simple HTTP GET request to the URL will trigger the script).

Alternatively, if you want to keep everything in Automation Studio, I will recommend you this Trailhead module on triggering automations with API.

2
  • Nice Idea with the Cloud Page. Is there any advantage in using JSON and not JavaScript?
    – Alex
    Commented Feb 20, 2023 at 11:59
  • 1
    That's totally up to you, @Alex - It all depends on how you intend to call the URL. IMHO JSON is most universal. Commented Feb 20, 2023 at 12:04
1

If you are comfortable with using REST API then this undocumented API may work for you.

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

The easiest way to get the "scriptObjectId" is you click on the Script Activity you want to execute. From your browser, it will look like something like this

https://mc.s10.exacttarget.com/cloud/#app/Automation%20Studio/AutomationStudioFuel3/%23ActivityModal/423/Your-Script-ObjectID

The last part after the last slash punctuation is your Script Object Id you need for the API call

Reference from Greg's blog.

2
  • 2
    I will not recommend relying on undocumented APIs in a production environment, as they might be changed or removed with no prior notice. Commented Feb 20, 2023 at 12:33
  • @LukasLunow I agree. Thank you for pointing out the risks.
    – Duc Le
    Commented Feb 20, 2023 at 12:45

You must log in to answer this question.

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