Expand my Community achievements bar.

SOLVED

PHP and Adobe Target Delivery API

Avatar

Level 3

Hello!

I am trying to implement the Adobe Target Delivery API using PHP code in order to get data about our current AB test experiences. This is what my request looks like:

 

$client = new Client();

$url = self::ADOBE_API_URL . '?client=' . self::ADOBE_CLIENT_ID . '&sessionId=' . self::ADOBE_SESSION_ID;

$headers = array();
$data = array();
$mboxes = array();
$request_data = array();

$mboxes[0]['name'] = self::ADOBE_TARGET_MBOX_SCOPE1;
$mboxes[0]['index'] = 1;
$mboxes[1]['name'] = self::ADOBE_TARGET_MBOX_SCOPE2;
$mboxes[1]['index'] = 2;
      
$headers['Content-Type'] = 'application/json';
$headers['cache-control'] = 'no-cache';

$data['context']['channel'] = self::ADOBE_CONTEXT_CHANNEL;
$data['property']['token'] = self::ADOBE_PROPERTY_TOKEN;
$data['prefetch']['mboxes'] = $mboxes;
$data['execute']['mboxes'] = $mboxes;

$request_data['headers'] = $headers;
$request_data['json'] = $data;

$response = $client->request( 'POST', $url, $request_data );
$response_data = json_decode( $response->getBody(), true );
return $response_data;

 

 

And this is the response I obtain. As you can see, the "options" property containing data about the experiences is missing:

 

Array
(
    [status] => 200
    [requestId] => ID
    [client] => CLIENT_NAME
    [id] => Array
        (
            [tntId] => TNT_ID
        )

    [edgeHost] => mboxedge37.tt.omtrdc.net
    [prefetch] => Array
        (
            [mboxes] => Array
                (
                    [0] => Array
                        (
                            [index] => 1
                            [name] => self::ADOBE_TARGET_MBOX_SCOPE1
                            [state] => STATE
                        )

                    [1] => Array
                        (
                            [index] => 2
                            [name] => self::ADOBE_TARGET_MBOX_SCOPE2
                            [state] => STATE
                        )

                )

        )

    [telemetryServerToken] => TELEMETRY_TOKEN
    [execute] => Array
        (
            [mboxes] => Array
                (
                    [0] => Array
                        (
                            [index] => 1
                            [name] => self::ADOBE_TARGET_MBOX_SCOPE1
                        )

                    [1] => Array
                        (
                            [index] => 2
                            [name] => self::ADOBE_TARGET_MBOX_SCOPE2
                        )

                )

        )

)

 

 

What am I possibly doing wrong?

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

It's the same idea as this serverState example, with a hybrid implementation, where you have the option to pre-fetch and cache many different offers/activities. That means you can then render them from the cache instead of having to make another network request to Target. 

View solution in original post

21 Replies

Avatar

Employee Advisor

If you don't have the options array included as part of the response, it's typically because you're not qualifying for any Target activities. How is your activity set up in Target? A/B test using Form Composer with an mbox name that matches one of the two you are including in your request?

Avatar

Level 3

Thanks, @alexbishop 

Yes, my activity is using Form Composer with an mbox name that matches the one in my request. However, the activity is not active yet. Should I include "qaMode" in my request? 

Avatar

Employee Advisor

Ah ok, yes that explains why you don't get the options response; if an activity is not active, you can only qualify for it by using that QA URL option and including that full query string in your request

Avatar

Level 3

Thanks, but it is still not working. 

My QA URL is: 

 

?at_preview_token=[TOKEN]&at_preview_index=1_2&at_preview_listed_activities_only=true&at_preview_evaluate_as_true_audience_ids=[AUDIENCE_ID]

 


and I am also adding "qaMode" to my request this way:

 

$data['qaMode']['token'] = TOKEN;
$data['qaMode']['listedActivitiesOnly'] = true;
$data['qaMode']['evaluateAsTrueAudienceIds'][0] = AUDIENCE_ID;
$data['qaMode']['previewIndexes'][0]['activityIndex'] = 1;
$data['qaMode']['previewIndexes'][0]['experienceIndex'] = 2;

 

 

Avatar

Level 3

One additional question: is it necessary to pass the "property->token" in this case?

Avatar

Employee Advisor

If you chose a Property as part of your activity setup:

alexbishop_0-1700741227131.png

Then you would need to pass the corresponding property token in your request. 

Do you have the option to activate the activity and see if you then get the correct response? That would help rule out if it's an issue with QA Mode or something else

Avatar

Level 3

Thanks!
No, I cannot activate the activity.

Where can I check the activity setup?

Avatar

Employee Advisor

I assume you can log into the Target UI; if so, then you can go into the activity and check to see what config has been applied, such as whether any Property configuration has been applied

alexbishop_0-1700743893255.png

Avatar

Level 3

The property that I am using in the request is correct.

I am also using the QA Mode and the QA URL, however, I still cannot see the activity details.

What am I missing?

Avatar

Employee Advisor

Might be worth trying without this parameter: 

$data['qaMode']['evaluateAsTrueAudienceIds'][0] = AUDIENCE_ID;


So you would have something like this:

alexbishop_0-1700747094349.png


It's actually only token & the previewIndexes array that are required within the qaMode object

Avatar

Level 3

Thanks!

On QA mode: do I have to add the QA parameters to the request URL?

These are my QA parameters: 

?at_preview_token=[TOKEN]&at_preview_index=1_2&at_preview_listed_activities_only=true&at_preview_evaluate_as_true_audience_ids=[AUDIENCE_ID]

Avatar

Employee Advisor

No need to add the QA params to the request URL; the request URL isn't important, unless someone has added an Audience Refinement as part of the activity configuration:
e.g. my LinkedIn Traffic audience below is defined as "URL contains cid=linkedin"

alexbishop_0-1700749409299.png

 

Avatar

Level 3

In my case, there is an Audience Refinement as part of the activity configuration: "Site Pages: Current Page Path contains /sign-up"

Avatar

Employee Advisor

Ok, so it's probably obvious to say this, but that does mean you will only qualify if the URL in the request contains /sign-up

Avatar

Level 3

@alexbishop, is there any support service where I can send a ticket and share my code so you can have a better understanding of the situation?

Avatar

Employee Advisor

Yes, you can contact Customer Care at customercare@adobe.com

 

There’s more info here about what details to include etc:

https://experienceleague.adobe.com/docs/target/using/cmp-resources-and-contact-information.html?lang...

Avatar

Level 3

@alexbishop, how can I know or see the mbox associated with an activity? I just noted this error "global mbox is not allowed in mboxes". What if all the activities are using global mboxes, how should I configure the request to get the activity data?

Avatar

Employee Advisor

Essentially "target-global-mbox" is reserved, so you can't use it as a "named" mbox in the requests you're making. You should be able to use any other values for the names of your mboxes though. 

Avatar

Level 3

Thanks again!

One more question: why am I getting a "state" attribute with some kind of encrypted value as part of the response of the "mbox"? By checking this link, I don't see the "state" anywhere. I mean something like this:

[prefetch] => Array
        (
            [mboxes] => Array
                (
                    [0] => Array
                        (
                            [index] => 1
                            [name] => [mbox_name]
                            [state] => [state]
                        )

                )

        )