Could someone please point out the mistake in the below script?

var restapi_url = "https://XXXXX.rest.marketingcloudapis.com/automation/v1/dataextracts";

var restapi_payload = '{"name": "Test DE extract","key": "966D6D48-1AA4-4812-ABD6-7A2DC5B751D5","description": "Trying Update","dataExtractTypeId": "bb94a04d-9632-4623-be47-daabc3f588a6","fileSpec": "TestingUpdateActivity.csv","intervalType": 0,"dataFields": [{"name": "ColumnDelimiter","type": "string","value": ","},{"name": "DECustomerKey","type": "string","value": "6F29911C-2741-43B9-BC35-26D5CFBC7F74"},{"name": "HasColumnHeaders","type": "bool","value": "True"},{ "name": "TextQualified", "type": "bool","value": "True"},{"name": "UsesLineFeed","type": "bool","value": "False"}]}';

var headerNames = ["Authorization"]; 
var s1="Bearer ";
var headerValues = "Bearer " + accessToken;

var req = new Script.Util.HttpRequest(restapi_url);
req.contentType = "application/json"
req.setHeader("Authorization", headerValues);
req.method = "POST"; 
req.postData = restapi_payload;
var restapi_result = req.send();

I am getting Bad Request (400) error.

Create automation soap api

<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
            <Objects xsi:type="Automation">
                <Name>System Data Views5</Name>
                        <Name>Test DE extract8</Name>
                                <ActivityObject xsi:type="DataExtractActivity">
                                    <CustomerKey>Test DE extract8</CustomerKey>
                                    <Name>Test DE extract5</Name>

It creates the automation but gives the following error:

enter image description here

  • 2
    I'd suggest getting it working in Postman first, then implementing it with SSJS. Postman will also generate the JS code for you -- as a place to start. – Adam Spriggs Sep 5 '20 at 14:51
  • Hi Adam, thank you for the suggestion. I tried with Postman, the status returned was 400. The error message said {"errors":[{"message":"Name already exists"},{"message":"CustomerKey already exists"}]}. I am trying to change the DE customer key of an existing data extract activity in the system. Is there anything that does this? REST/SOAP/SSJS? – Priyanka Sep 5 '20 at 16:08
  • 1
    Have you tried a patch instead of a post? – EazyE Sep 5 '20 at 17:09
  • Thanks a lot! EazyE, that worked. – Priyanka Sep 7 '20 at 11:13

Exactly as @EazyE commented, you are doing a POST which is a 'create' and to update you need to do a PATCH which is update. Although the Endpoint is mostly the same, the Method has to be different.

There is also a slight difference in that you need to include the dataextractid inside the URL at the end for the PATCH as well as in the JSON in the body.

Making the update call like so:

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

    "dataExtractDefinitionId": "xxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "name": "myExtract",
    "key": "myExtract",
    "description": "",
    "dataExtractTypeId": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
    "fileSpec": "myFile.zip",
    "intervalType": 0,
    "startDate": "01/01/2014",
    "endDate": "01/30/2014",
    "dataFields": [
            "name": "AccountIDs",
            "type": "string",
            "value": "*"
            "name": "Attributes",
            "type": "string",
            "value": ""
        .... etc.
  • Thanks a lot Gortonington, that worked! – Priyanka Sep 7 '20 at 11:13
  • Also, when I call the create Automation SOAP , using this data extract activity. The Automation is created successfully but when I open the activity step, it gives me the following error(attached in the initial question) – Priyanka Sep 7 '20 at 11:32
  • @Gortonington how can we do the same thing for file transfer activity? – Rohit Oct 23 '20 at 7:10

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.