Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Extract action #146

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

fbellgr
Copy link

@fbellgr fbellgr commented Mar 2, 2021

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);
    }
})();

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant