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: ''
}
]
*/