2

I am facing an issue where I am not able to update the DataExtract (File Convert) activity via Rest below API in SSJS script activity.

In the API response I am getting below error

API Responsse : {"errors":[{"message":"The following field is required: 'DataExtractTypeId'."}]}

Though I am passing the DataExtractTypeId in the request payload , still I am getting this error.

Note : The same request works fine via POSTMAN, but via cloud Page , it is giving above error

Details are as follows:

URI : https:{{hostname}}.rest.marketingcloudapis.com/automation/v1/dataextracts/{{dataExtractDefId}}

METHOD: PATCH

REQUEST:

{
    "name": "Email_FileConvert",
    "key": "Email_FileConvert",
    "description": "",
    "fileSpec": "emails_verified_test.csv",
    "dataFields": [
        {
            "name": "ConvertTo",
            "type": "dropdown",
            "value": "UTF8"
        },
        {
            "name": "Folder",
            "type": "string",
            "value": ""
        },
        {
            "name": "IsFileInSafeHouse",
            "type": "bool",
            "value": "True"
        }
    ],
    "dataExtractDefinitionId": {{dataExtractDefId}},
    "dataExtractTypeId": "35314e6a-929e-487e-81f8-70366d7679d3",
    "createdBy": 12345,
    "modifiedBy": 12345,
    "intervalType": 0,
    "extractTypeName": "File Convert"
}

**ssjs headers:**

 var auth = "Bearer " + accessToken;
          var req = new Script.Util.HttpRequest(requestUrl);
          req.emptyContentHandling = 0;
          req.retries = 2;
          req.continueOnError = true;
          req.contentType = "application/json"
          req.setHeader("Authorization",auth);
          req.method = "PATCH";
          req.postData =payload;
          var resp = req.send();
          varresponseBody=Platform.Function.ParseJSON(String(resp.content));
          Write('API RESPONSE:'+Stringify(responseBody));

Also, the below request for Updating DataExtract-Data Extention activity type, it is getting updated successfully from the CLoud Page SSJS

URI https://{{et_subdomain_test}}.rest.marketingcloudapis.com/automation/v1/dataextracts/{{extract_def_id}}

Request:

{
    "name": "Emails_Export",
    "key": "Emails_Export",
    "description": "",
    "fileSpec":"emails_verified_test.csv",
    "dataFields": [
        {
            "name": "ColumnDelimiter",
            "type": "string",
            "value": ","
        },
        {
            "name": "DECustomerKey",
            "type": "string",
            "value": "Verfied_Emails_Export_DE"
        },
        {
            "name": "HasColumnHeaders",
            "type": "bool",
            "value": "True"
        },
        {
            "name": "TextQualified",
            "type": "bool",
            "value": "True"
        },
        {
            "name": "UsesLineFeed",
            "type": "bool",
            "value": "False"
        }
    ],
    "dataExtractDefinitionId":{{extract_def_id}},
    "dataExtractTypeId": "bb94a04d-9632-4623-be47-daabc3f588a6",
    "createdBy": 123456,
    "modifiedBy": 123456,
    "intervalType": 0,
    "extractTypeName": "Data Extension Extract"
}
4
  • 2
    If the same payload works from POSTman, but not a cloudpage, the error most likely isn't in the payload. What you didn't share are the request headers. Can you verify that your cloudpage is sending the correct content-type header (application/json) ? Maybe postman sets that correctly for you without you knowing, and a cloudpage isn't so generous. Feb 25, 2022 at 11:59
  • @Jonas Lamberty I have updated in the request. Please check
    – Coder_geek
    Feb 25, 2022 at 12:19
  • 1
    Issue has been resolved now. Error was while adding payload to request I missed to convert into string i.e req.postData = Stringify(payload)
    – Coder_geek
    Feb 25, 2022 at 17:10
  • Great to hear! Would you mind putting this as an answer and accepting it for others to reference. Feb 25, 2022 at 20:31

1 Answer 1

0

Issue has been resolved.

Error was while adding payload to request I missed to convert into string i.e req.postData = Stringify(payload)

You must log in to answer this question.

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