0

I'm building a mini app project using the Node SDK, but something I'm having trouble with is pulling data across all Business Units.

The SFMC account I'm working in has multiple BU's and I want to write a function that pulls ALL the DEs from ALL the BU's. The function I have written so far is;

const sfmcNode = new ET_Client(
    clientId, 
    clientSecret, 
    stack, 
    {
        origin, 
        authOrigin, 
        soapOrigin, 
        authOptions: { 
            authVersion: 2, 
        }   
    }
); 

const getAllDataExtensions = async () => {
    
    var options = {
        props: ['Name', 'CustomerKey', 'ObjectID', 'Client.ID'],
        filter: {
            leftOperand: 'Client.ID'
            , operator: 'isNotNull'
            , rightOperand: ''
        }
    }
    
    return await new Promise( (resolve, reject) => {
        const de = sfmcNode.dataExtension(options);
        de.get((err,res) => {
            try {
                resolve(res.body.Results)
            } catch (err) {
                console.log(err)
            }
            
        }) 
    })

}

The function above works, but it's only returning all the DE's from a particular business unit. Any idea how I can write the function to search ALL the business units?

The only thing that kind of works is passing in the accountId when instantiating the ET_Client, but that still only returns results from a particular BU... see below

const sfmcNode = new ET_Client(
    clientId, 
    clientSecret, 
    stack, 
    {
        origin, 
        authOrigin, 
        soapOrigin, 
        authOptions: { 
            authVersion: 2, 
            accountId: BusinessUnitID,                                   
            scope: 'data_extensions_read data_extensions_write',
            applicationType: 'server'
        }   
    }
); 

I think at the very least I would like a way to get an array of Business Unit IDs so that I can loop over them to create ET_Clients to use and get all the necessary data.

EDIT I've also tried making a request to the BusinessUnit object via SOAP API, but only got information for the Business Unit that I'm only getting the results for.

const sfmcSoap = new FuelSoap({
    auth: {
        clientId
        , clientSecret
        , authUrl: authOrigin + 'v2/token'
        , authOptions: {
            authVersion: 2,
        }
    }
    , soapOrigin

});

var retrieveOptions = {
    filter: {
        leftOperand: 'Name',
        operator: 'isNotNull',
        rightOperand:  ''
    }
}


sfmcSoap.retrieve(
    'BusinessUnit'
    , ['Name', 'AccountType']
    , retrieveOptions
    , (err, response) => {
        if (err) {
            console.log(err)
        } else {
            console.log(response.body.Results)
        }   
})


// RESULT:
/*
[
  {
    PartnerKey: '',
    ObjectID: '',
    AccountType: 'BUSINESS_UNIT',
    Name: 'TestBU',
    Subscription: ''
  }
]

*/
6
  • You can get a list of BU on this object: developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/…
    – EazyE
    Commented Nov 30, 2020 at 0:32
  • I tried that but it unfortunately just gave me the information for the single BU
    – balwill
    Commented Nov 30, 2020 at 0:57
  • 1
    Did you make the call at the EID / parent / top level account?
    – EazyE
    Commented Nov 30, 2020 at 1:29
  • Yeah, i passed the Parent MID within the accountId parameter within authOptions. I still only receive results for that particular BU
    – balwill
    Commented Nov 30, 2020 at 19:25
  • Has the API User access to all BUs?
    – DonL
    Commented Dec 1, 2020 at 8:03

1 Answer 1

1

Make sure to use queryAllAccounts.

var retrieveOptions = {
    filter: {
        leftOperand: 'Name',
        operator: 'isNotNull',
        rightOperand:  ''
    },
    queryAllAccounts: true
}

You must log in to answer this question.

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