DocumentationTarget Developer Guide

Get Attributes (Java)

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

Attributes TargetClient.getAttributes(TargetDeliveryRequest targetRequest, String ...mboxes)

Parameters

NameTypeRequiredDefaultDescription
targetRequestTargetDeliveryRequestYesNoneThe same target request as used for Get Offers​
mboxNamesvar-args arrayNoNoneA var-args array of mbox names

Result

An Attributes object is returned from TargetClient.getAttributes() which has the following methods:

NameTypeDescription
getBoolean(mboxName, key)BooleanReturns the value for a specified mbox name and attribute key
getString(mboxName, key)StringReturns the value for a specified mbox name and attribute key
getInteger(mboxName, key)IntegerReturns the value for a specified mbox name and attribute key
getDouble(mboxName, key)DoubleReturns the value for a specified mbox name and attribute key
toMboxMap(mboxName)MapReturns a simple Map with key value pairs
getResponse()TargetDeliveryResponseReturns the response object normally returned by getOffers

Example

Java

ClientConfig clientConfig = ClientConfig.builder()
        .client("acmeclient")
        .organizationId("1234567890@AdobeOrg")
        .build();

TargetClient targetJavaClient = TargetClient.create(clientConfig);

TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder()
        .context(new Context().channel(ChannelType.WEB))
        .build();

Attributes offerAttributes = targetJavaClient.getAttributes(targetDeliveryRequest, "demo-engineering-flags");

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

//returns a simple Map representing the mbox offer
Map<String, Object> engineeringFlags = offerAttributes.toMboxMap("demo-engineering-flags");

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

String assetUrl = "http://" + engineeringFlags.cdnHostname + "/path/to/asset";
recommendation-more-help
6906415f-169c-422b-89d3-7118e147c4e3