---
name: ssjs-server-side-javascript
description: "Use this skill when writing, debugging, or reviewing Server-Side JavaScript (SSJS) in Salesforce Marketing Cloud — Script Activities, Cloud Pages, and Landing Pages. Covers WSProxy for SOAP API access, Script.Util.HttpRequest for outbound REST calls, error handling patterns, execution limits, and SSJS/AMPscript interoperability. NOT for AMPscript-only personalization logic inside Email Studio sends, not for standard Apex (Salesforce Platform), and not for client-side JavaScript in Experience Cloud or LWC."
category: apex
salesforce-version: "Spring '25+"
well-architected-pillars:
- Security
- Reliability
- Performance
triggers:
- "I need to call a SOAP API from a Marketing Cloud Script Activity without writing raw XML"
- "My Script Activity is failing silently and I don't know where the error is"
- "How do I make an outbound HTTP REST call from a Cloud Page using SSJS"
- "WSProxy is returning null and I don't understand why my retrieve filter is wrong"
- "My SSJS uses let and const but it throws a syntax error in Marketing Cloud"
- "Script Activity timed out after 30 minutes — how do I handle long-running data operations"
- "I want to mix AMPscript and SSJS in the same Cloud Page content block"
- "How do I log debug output from inside a Script Activity to diagnose failures"
tags:
- ssjs
- marketing-cloud
- script-activity
- wsproxy
- cloud-pages
- automation-studio
- http-functions
- ampscript-interop
inputs:
- "The SSJS file or Script Activity content block to review or write"
- "The target API endpoint (SOAP or REST) the script needs to call"
- "The data extension name and field list if doing WSProxy retrieve/upsert"
- "Any known error messages or Activity failure codes"
- "Execution context: Script Activity, Cloud Page, or Landing Page"
outputs:
- "Corrected or authored SSJS wrapped in
```
**Why not the alternative:** Using AMPscript `UpsertDE()` works for small single-record updates inside sends, but it cannot handle batch operations, does not provide programmatic status checking, and is not appropriate for Automation Studio Script Activities.
### Outbound REST Call with Error Logging
**When to use:** Pulling data from an external REST API (CRM, ERP, custom backend) inside a Script Activity and writing results to a Data Extension.
**How it works:**
```javascript
```
---
## Decision Guidance
| Situation | Recommended Approach | Reason |
|---|---|---|
| Retrieve/upsert Marketing Cloud objects (Subscribers, DEs, Sends) | WSProxy | Handles auth, paging, SOAP envelope automatically; lower overhead than raw HTTP |
| Call external REST API from Script Activity | Script.Util.HttpRequest | Designed for outbound HTTP; handles headers, methods, retries |
| Per-subscriber email personalization at send time | AMPscript | AMPscript has subscriber context; SSJS does not run per-subscriber during sends |
| Complex data transformation, looping, conditional logic in Automation | SSJS Script Activity | SSJS supports full procedural logic; AMPscript is template-oriented |
| Debugging a failing Script Activity | Write() + try/catch | Write() outputs to Activity log; uncaught exceptions give no diagnostic info |
| Need to call a SOAP API without WSProxy | Script.Util.HttpRequest + raw XML | Last resort only — WSProxy is always preferred for SOAP |
---
## Recommended Workflow
Step-by-step instructions for an AI agent or practitioner working on this task:
1. **Confirm execution context** — identify whether this is a Script Activity, Cloud Page, or Landing Page. Script Activity: check timeout risk (30-min limit). Cloud Page: check whether code needs to be synchronous and handle subscriber context.
2. **Identify the API target** — if interacting with Marketing Cloud objects (Data Extensions, Subscribers, Sends), plan to use WSProxy. If calling external endpoints, plan to use Script.Util.HttpRequest.
3. **Author the SSJS block** — wrap all code in `