FuelSDK-Node-SOAP icon indicating copy to clipboard operation
FuelSDK-Node-SOAP copied to clipboard

Extract action

Open fbellgr opened this issue 3 years ago • 0 comments

I noticed someone else has already made a pull request for FuelSoap.prototype.extract. Here is a very simple implementation with absolutely nothing else, hoping it helps speed things along.

To help speed things along even more, following are explanations on how to use it successfully.

Notes:

  • I make use of version 2 auth options

  • The file will be outputted in the Export directory of the enhanced FTP, given that you supply the correct ID, which may be specific to your account. To find the correct ID, use the API to retrieve the ExtractDescription object. My example uses the "Data Extension Extract" definition. You should find something like this:

{
  "PartnerKey": "",
  "ObjectID": "YOUR REQUEST ID",
  "Name": "Data Extension Extract",
  "Parameters": {
    "Parameter": [
      {
        "Name": "ApplyTimeZone",
        "DataType": "bool",
        "DefaultValue": "false",
        "IsOptional": "true"
      },
      {
        "Name": "ConvertToASCII",
        "DataType": "bool",
        "DefaultValue": "true",
        "IsOptional": "true"
      },
      ...

How to use it:

const options = {
    "auth": {
        "authOptions": {
            "applicationType": "server",
            "authVersion": 2,
            "accountId": "#MID#"
        },
        "authUrl": "https://#YOUR-SUPDOMAIN#.auth.marketingcloudapis.com/v2/token",
        "clientId": "#CLIENTID#",
        "clientSecret": "#CLIENTSECRET#"
    }
};

const FuelSoap = require("fuel-soap");

const SoapClient = new FuelSoap(options);

let def = {
    ID: "YOUR REQUEST ID",
    Parameters: {
        Parameter: [
            // The extract description you retrieve with the API contains a list of parameters and possible values. Not all of them works.
            // Here I use a few of them
            {
                Name: "OutputFileName",
                Value: "test-extractc.csv" // customize to your liking, no slash for backslash
            },
            {
                Name: "DECustomerKey",
                Value: "import_dev_test" // use your own DE customer key
            },
            {
                Name: "TextQualified",
                Value: "true"
            },
            {
                Name: "HasColumnHeaders",
                Value: "true"
            },
            // Doc says you have to set those three parameters
            {
                Name: "StartDate",
                Value: "1/1/1900 1:00:00 AM"
            },
            {
                Name: "EndDate",
                Value: "1/1/1900 1:00:00 AM"
            },
            {
                Name: "_AsyncID",
                Value: "0"
            }
        ]
    }
};

(async () => {
    try {
        var result = await require("util").promisify(SoapClient.extract).call(SoapClient, def);
        console.log(JSON.stringify(result.body, null, 2))
    } catch (e) {
        console.error(e);
    }
})();

fbellgr avatar Mar 02 '21 16:03 fbellgr