Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

how to fetch data from an API and render experience which contain response of the API

Avatar

Avatar
Validate 1
Level 2
shridhar_sahu
Level 2

Likes

3 likes

Total Posts

36 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 2
shridhar_sahu
Level 2

Likes

3 likes

Total Posts

36 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile
shridhar_sahu
Level 2

25-01-2019

Hi,

I have an use case in which i need to fetch data from an API and render experience which contain response of the API

For accomplishing above scenario i am using usign DTM and adobe target.

  1. i have created a data element using custom script which contain XMLHttpRequest
  2. i have created a page load rule which triggers on dom ready from where i am passing value as a mbox global parameter to adobe target
  3. i am using mbox global parmeter in adobe target and rendering experience.

After page load everything works fine in console but i'm getting response as empty string in adobe experience cloud debugger.

Can any one let me know where i am going wrong?

Below is the custom script code for data element.

    var request = new XMLHttpRequest();

    request.onreadystatechange = function() {

        if (this.readyState == 4 && this.status == 200) {

               console.log(this.responseText);

               var response = JSON.parse(this.responseText);

               return response.id; //the data element will return id of response

        }

    };

    request.open('GET', 'https://examplev1/query?v=20160910&query=hi&lang=en-us&sessionId=session123', true);

    request.setRequestHeader("Content-type", "application/json");

    request.send();

Replies

Avatar

Avatar
Give Back 5
Level 7
Eric_Vidana
Level 7

Likes

154 likes

Total Posts

150 posts

Correct Reply

37 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 25
Give Back 10
Give Back
View profile

Avatar
Give Back 5
Level 7
Eric_Vidana
Level 7

Likes

154 likes

Total Posts

150 posts

Correct Reply

37 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 25
Give Back 10
Give Back
View profile
Eric_Vidana
Level 7

05-02-2019

I am not sure what the question is. Is your XHR call for Adobe Target? If you are already in the web layer, you should go get a copy of at.js in order for those calls to be structured properly.

at.js functions