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.