DocumentationTargetTarget Developer Guide

Get Attributes (Node.js)

Last update: July 17, 2023
  • Topics:
  • APIs/SDKs

CREATED FOR:

  • Developer

Description

getAttributes() is used to fetch experimentation and personalized experiences from Target and extract attribute values.

Method

getAttributes

TargetClient.getAttributes(mboxNames: Array, options: Object): Promise

Parameters

NameTypeRequiredDefault
mboxNamesArrayYesNone
optionsObjectNoNone

Promise

The Promise returned by TargetClient.getAttributes() resolves an object with the following methods:

MethodReturn TypeDescription
getValue(mboxName, key)AnyReturns the value for a specified mbox name and attribute key
asObject(mboxName)ObjectReturns a simple json object with key value pairs
getResponse()getOffers ResponseReturns the response object normally returned by getOffers

Example

Node.js

const TargetClient = require("@adobe/target-nodejs-sdk");
const CONFIG = {
  client: "acmeclient",
  organizationId: "1234567890@AdobeOrg"
};

const targetClient = TargetClient.create(CONFIG);
const offerAttributes = await targetClient.getAttributes(["demo-engineering-flags"]);


//returns just the value of searchProviderId from the mbox offer
const searchProviderId = offerAttributes.getValue("demo-engineering-flags", "searchProviderId");

//returns a simple JSON object representing the mbox offer
const engineeringFlags = offerAttributes.asObject("demo-engineering-flags");

//  the value of engineeringFlags looks like this
//  {
//      "cdnHostname": "cdn.cloud.corp.net",
//      "searchProviderId": 143,
//      "hasLegacyAccess": false
//  }

const assetUrl = `http://${engineeringFlags.cdnHostname}/path/to/asset`;
recommendation-more-help
6906415f-169c-422b-89d3-7118e147c4e3