---
title: Javascript API
slug: docs/javascript-api
docTags: 
createdAt: 2024-11-28T08:40:09.027Z
---

Demo System Profile Viewer provides a JavaScript API, which lets you fetch profile information, experience events and offers in your own JavaScript code. This is useful for scenarios like:

- Pre-populating forms with profile information
- Custom visualization of experience events
- Getting offers for web personalization

You can interact with Profile Viewer JavaScript API through a global DSN object and its functions. Under the hood, it takes care of authentication, passing ECID etc.&#x20;

## Initialization

DSN JavaScript API takes a moment to initialize so it's best to start using it after dsnApiReady event:

:::BlockQuote
window\.addEventListener('dsnApiReady', function() \{  console.log(window\.DSN);});
:::

## DSN.getProfile()

**Parameters:** none

**Returns:** promise which resolves with raw response from AEP API containing unified profile object.

:::BlockQuote
DSN.getProfile().then(function(profile) \{  console.log(profile)})
:::

## DSN.getExperienceEvents()

**Parameters:** none

**Returns:** promise which resolves with raw response from AEP API containing a list of experience events for current profile.

:::BlockQuote
DSN.getExperienceEvents().then(function(experienceEvents) \{  console.log(experienceEvents)})
:::

## DSN.getOffer(decisionScope, rawResponse)

**Parameters:**
**decisionScope -&#x20;**&#x6F;bject containing activityId and placementId, copied from Offers UI



![](https://api.archbee.com/api/optimize/bAgVaanSi1tFmfc8PghaH/CD6VCTtOotElLzgC_zTVl_image.png)

**rawResponse&#x20;**- if true, returns a raw response from Offer Decisioning API, otherwise only the offer content will be returned.&#x20;

**Returns:** promise which resolves with offer content or raw response (depending on rawResponse parameter) from Offer Decisioning API for given decision scope and current ECID.

::::Tabs
:::Tab{title="callback"}
```javascript
// by default, only offer content is returned
DSN.getOffer({
  "xdm:activityId":"xcore:offer-activity:12d395521494f789",
  "xdm:placementId":"xcore:offer-placement:12c179867ece8ad8"
}).then(function(offerContent) {
  console.log(offerContent)
})

// to get the whole response, pass true as rawResponse parameter
DSN.getOffer({
  "xdm:activityId":"xcore:offer-activity:12d395521494f789",
  "xdm:placementId":"xcore:offer-placement:12c179867ece8ad8"
}, true).then(function(rawResponse) {
  console.log(rawResponse)
});
```
:::

:::Tab{title="async/await"}
```javascript
// by default, only offer content is returned
const offerContent = await DSN.getOffer({
  "xdm:activityId":"xcore:offer-activity:12d395521494f789",
  "xdm:placementId":"xcore:offer-placement:12c179867ece8ad8"
})

// to get the whole response, pass true as rawResponse parameter
const rawResponse = await DSN.getOffer({
  "xdm:activityId":"xcore:offer-activity:12d395521494f789",
  "xdm:placementId":"xcore:offer-placement:12c179867ece8ad8"
}, true)
```
:::
::::

