[SalesForce] Create or update Automation with Marketing Cloud REST API new endpoint

there is an endpoint to retrieve automation using Rest API with OAuth2 token and GET method:

https://{{tenant}}.rest.marketingcloudapis.com/automation/v1/automations/{{id}}

In the response you will get an automation in .json format:

{
    "id": "6d502423-ddf4-4c54-abbe-f5c3f2cfcb49",
    "name": "Tracking Extract Report",
    "description": "",
    "key": "af759c22-9271-1e75-f695-5f79de858e8a",
    "typeId": 1,
    "type": "scheduled",
    "statusId": 4,
    "status": "PausedSchedule",
    "categoryId": 681,
    "lastRunTime": "2019-04-26T05:31:46.21",
    "lastRunInstanceId": "5a889ff1-7823-457e-a17b-a0c3d879091c",
    "schedule": {
        "id": "111fdd2e-a68d-4117-5a60-322beb3436dc",
        "typeId": 2,
        "startDate": "2019-04-11T18:30:00",
        "endDate": "2079-06-06T00:00:00",
        "scheduledTime": "0001-01-01T07:00:00",
        "rangeTypeId": 1,
        "occurrences": 527286,
        "pattern": "<Pattern><PatternType>0</PatternType><HourInterval>1</HourInterval></Pattern>",
        "icalRecur": "FREQ=HOURLY;UNTIL=20790606T080000;INTERVAL=1",
        "timezoneName": "Romance Standard Time",
        "scheduleStatus": "paused",
        "timezoneId": 7
    },
    "steps": [
        {
            "id": "fa8452cb-455b-427e-bd03-22f3be317cba",
            "name": "",
            "step": 1,
            "activities": [
                {
                    "id": "584e75ae-ee58-472b-b689-9def0c25eaba",
                    "name": "Extract Reports Creation",
                    "activityObjectId": "05d87588-19d3-4829-bf4b-c1a5c2e5d2a9",
                    "objectTypeId": 73,
                    "displayOrder": 1
                }
            ]
        },
        {
            "id": "bc31b39d-5b71-4cd8-b56c-948009876a28",
            "name": "",
            "step": 2,
            "activities": [
                {
                    "id": "83b7cc0a-b0c0-45f9-9547-d8d6cd9fde79",
                    "name": "Export Tracking Report To FTP",
                    "activityObjectId": "0a955058-55de-47a0-a95e-4a338a564bb7",
                    "objectTypeId": 53,
                    "displayOrder": 1
                }
            ]
        },
        {
            "id": "4b828cab-1216-4859-bb24-d329a89f080d",
            "name": "",
            "step": 3,
            "activities": [
                {
                    "id": "6c33d219-75bc-4fe2-968a-5fbaa46fee4a",
                    "name": "Unzip_Tracking_Report",
                    "activityObjectId": "a050199d-d7b3-4f04-9d3c-c3208f32c50c",
                    "objectTypeId": 53,
                    "displayOrder": 1
                }
            ]
        },
        {
            "id": "d23dfc81-0a55-4ee9-8265-9aff4b85ab92",
            "name": "",
            "step": 4,
            "activities": [
                {
                    "id": "5e0eaa08-853e-4ecc-8490-4250b2e062f2",
                    "name": "Import_TrackingExtract_SendJobs",
                    "activityObjectId": "3125f806-1b15-e911-a2d0-1402ec8ca115",
                    "objectTypeId": 43,
                    "displayOrder": 1,
                    "targetDataExtensions": [
                        {
                            "id": "284c8568-1515-e911-a2d0-1402ec8ca115",
                            "name": "TrackingExtract_SendJobs",
                            "key": "D5C31190-611A-4817-9CBF-D023E1D9B646",
                            "description": "",
                            "rowCount": 129
                        }
                    ]
                },
                {
                    "id": "0d43fe57-3b10-4953-a9e2-c230903061c0",
                    "name": "Import_TrackingExtract_Sent",
                    "activityObjectId": "c7d5f633-6f15-e911-a2d0-1402ec8ca115",
                    "objectTypeId": 43,
                    "displayOrder": 2,
                    "targetDataExtensions": [
                        {
                            "id": "a40e718b-6c55-e911-a2d0-1402ec8ca115",
                            "name": "TrackingExtract_Sent",
                            "key": "E054D3A6-720A-4A67-A737-28231B52ACFC",
                            "description": "",
                            "rowCount": 0
                        }
                    ]
                },
                {
                    "id": "6ae75778-52ad-4dea-85f5-92ed017694c8",
                    "name": "Import_TrackingExtract_Opens",
                    "activityObjectId": "21223554-6f15-e911-a2d0-1402ec8ca115",
                    "objectTypeId": 43,
                    "displayOrder": 3,
                    "targetDataExtensions": [
                        {
                            "id": "52935236-6d15-e951-a2d0-1402ec8ca115",
                            "name": "TrackingExtract_Opens",
                            "key": "D2FED15B-DB4F-42DC-8025-F628C583ABA0",
                            "description": "",
                            "rowCount": 0
                        }
                    ]
                },
                {
                    "id": "7c400533-47e1-4bff-bc5a-8868b6db18dd",
                    "name": "Import_TrackingExtract_Clicks",
                    "activityObjectId": "c88455ef-6f15-e911-a2d0-1402ec8ca115",
                    "objectTypeId": 43,
                    "displayOrder": 4,
                    "targetDataExtensions": [
                        {
                            "id": "3ec69c9e-6515-e911-a2d0-1402ec8ca115",
                            "name": "TrackingExtract_Clicks",
                            "key": "1D424B60-49C8-43FC-89A8-CD4000BE114F",
                            "description": "",
                            "rowCount": 0
                        }
                    ]
                },
                {
                    "id": "bde26ad7-50b1-4f5b-b15b-2222ac072e6e",
                    "name": "Import_TrackingExtract_Bounces",
                    "activityObjectId": "fcf75f09-7015-e911-a2d0-1402ec8ca115",
                    "objectTypeId": 43,
                    "displayOrder": 5,
                    "targetDataExtensions": [
                        {
                            "id": "bc56343e-6515-e911-a2d0-1402ec8ca115",
                            "name": "TrackingExtract_Bounces",
                            "key": "F3578B67-AEEC-4C2B-8099-D621ECD7F22B",
                            "description": "",
                            "rowCount": 2
                        }
                    ]
                },
                {
                    "id": "142f4ce3-1534-4056-a1be-e7ef79546e43",
                    "name": "Import_TrackingExtract_NotSent",
                    "activityObjectId": "5d65ce75-7115-e911-a2d0-1402ec8ca115",
                    "objectTypeId": 43,
                    "displayOrder": 6,
                    "targetDataExtensions": [
                        {
                            "id": "06e55e39-7115-e911-a2d0-1402ec8ca115",
                            "name": "TrackingExtract_NotSent",
                            "key": "CBCCCA93-D0D8-4CD8-B3FF-8C891410AC9D",
                            "description": "",
                            "rowCount": 0
                        }
                    ]
                },
                {
                    "id": "3aa11ca3-14b7-457f-97eb-8e53b2c3c1ba",
                    "name": "Import_TrackingExtract_Unsubs",
                    "activityObjectId": "c529bfc2-7915-e911-a2d0-1402ec8ca115",
                    "objectTypeId": 43,
                    "displayOrder": 7,
                    "targetDataExtensions": [
                        {
                            "id": "9cb22265-7915-e911-a2d0-1402ec8ca115",
                            "name": "TrackingExtract_Unsubs",
                            "key": "8B7126DC-4776-4751-8581-3E1C1C7A9BBD",
                            "description": "",
                            "rowCount": 1
                        }
                    ]
                },
                {
                    "id": "4596f1ba-dba5-45cd-9546-11d05d176616",
                    "name": "Import_TrackingExtract_Surveys",
                    "activityObjectId": "35e897a2-7d15-e911-a2d0-1402ec8ca115",
                    "objectTypeId": 43,
                    "displayOrder": 8,
                    "targetDataExtensions": [
                        {
                            "id": "f25c1d45-7d15-e911-a2d0-1402ec8ca115",
                            "name": "TrackingExtract_Surveys",
                            "key": "AEAED33D-FBE1-44CD-BB9B-9DEDF788116D",
                            "description": "",
                            "rowCount": 0
                        }
                    ]
                }
            ]
        }
    ]
}

There is also a POST method to create a new Automation with the endpoint:

https://{{tenant}}.rest.marketingcloudapis.com/automation/v1/automations/

and a PATCH method to update an existing Automation with the endpoint:

https://{{tenant}}.rest.marketingcloudapis.com/automation/v1/automations/{{id}}

In the POST/PATCH request you need to delete targetDataExtensions array for query activity. And it works, but:

  • created/updated Automation doesn't have a schedule "starting source" is empty
  • it works only for Automation with only one step (may have more than one activity in this step)

If Automation contains more than one step, the response during creation is:

{  
   errors:[  
      {  
         message:'Invalid task collection'
      }
   ]
}

and during update:

{  
       message:'Internal Server Error',
       errorcode:0,
       documentation:'https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/error-handling.htm'
}

Maybe someone tried these endpoint and have an idea what I need to have to:

  • be able to create/update Automation with more than one step
  • have scheduled Automations

Best Answer

I made some investigation and think that to create/update Automation using REST, it is needed to use .json payload in this format:

{
    "id": "e906af34-4a19-42e9-9ce2-ac6413a77a09",
    "legacyId": "X0p0TVdZSUxWZ09sVEV0dlJiTk5CUToyNTow",
    "name": "Maciej_testAut_20190513_1721",
    "description": "ddddd",
    "key": "Maciej_testAut_20190513_1721",
    "categoryId": 409,
    "statusId": 4,
    "lastSavedDate": "2019-05-13T07:43:59.137",
    "lastSavedByName": "Maciej Barnas",
    "createdDate": "2019-05-13T06:27:06.597",
    "createdByName": "DEV integration for Metadata Tool - v2 app user",
    "updateInProgress": false,
    "steps": [
        {
            "annotation": "",
            "stepNumber": 0,
            "activities": [
                {
                    "id": "9ba08e57-57b8-4485-b219-e1ddfd6e6019",
                    "name": "Maciej_testQuery_2",
                    "description": "",
                    "activityObjectId": "fb0533a4-a7d5-4579-a766-cd7e4b047e74",
                    "objectTypeId": 300,
                    "displayOrder": 0,
                    "serializedObject": ""
                }
            ]
        },
        {
            "annotation": "",
            "stepNumber": 1,
            "activities": [
                {
                    "id": "b5cfb339-52b1-45a7-a75e-c20ac8fdecdf",
                    "name": "Maciej_testQuery_1",
                    "description": "",
                    "activityObjectId": "51f05855-88a9-403c-a3b0-d4b42ac7db91",
                    "objectTypeId": 300,
                    "displayOrder": 0,
                    "serializedObject": ""
                }
            ]
        }
    ],
    "startSource": {
        "typeId": 1,
        "schedule": {
            "scheduleTypeId": 2,
            "startDate": "2019-05-13T16:00:00",
            "endDate": "2019-05-13T16:00:00",
            "rangeTypeId": 0,
            "occurrences": 1,
            "icalRecur": "FREQ=HOURLY;COUNT=1;INTERVAL=1",
            "timezoneId": 5,
            "statusId": 0
        }
    }
}

To create use POST, to update use PATCH. The endpoints are the same as I noticed in my question.

But as you can see the format, which you can retrieve using GET with the endpoint:

https://{{tenant}}.rest.marketingcloudapis.com/automation/v1/automations/{{id}}

contains e.g. "schedule" and "steps" part is different. But to create/update we need to have "startSource" and "steps" in other way.

Related Topic