---
title: "Serving MomentPerks in Mobile Apps"
description: "This playbook provides a high-level guide for implementing Moments in your mobile application using the MomentScience MomentPerks API."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.momentscience.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Serving MomentPerks in Mobile Apps

# Overview

This playbook provides a high-level guide for implementing Moments in your mobile application using the MomentScience [MomentPerks API](https://docs.momentscience.com/api-resources/momentperks-api).

## What is a Moment?

A **Moment** is a contextual experience that presents one or more personalized offers at meaningful points in a user's journey, such as after a purchase, upon completing a task, or during a key interaction. These Moments help you:

- Enhance user engagement with timely, relevant perks
- Drive incremental revenue by surfacing claimable offers
- Maintain full control over how and where offers appear in your app

Using the [MomentPerks API](https://docs.momentscience.com/api-resources/momentperks-api) , your app can fetch Moments dynamically and render them with your own UI components.

# Integration Steps

The following steps outline the general integration flow for using the [MomentPerks API](https://docs.momentscience.com/api-resources/momentperks-api) . These steps apply to all mobile platforms and should be followed before implementing a platform-specific SDK (e.g., Flutter, iOS, Android, React Native).

## Step 1: Create an API Key

Before making API requests, you need to generate an API key from the MomentScience dashboard.

**To create an API key:**

1. **Log In**: Sign in to your MomentScience account.
2. **Go to Profile**: Navigate to the **Profile** section in the dashboard.
3. **Generate API Key**: Click the **Generate API Key** button.
4. **Name the Key**: Enter a descriptive name (for example, "Test API Key" or "Production API Key").
5. **Set Scopes**: Select the appropriate access scopes. Make sure the **Ads/Offers** scope is selected.
6. **Generate**: Click **Generate** to create the API key.

Pass this key in the `api_key` query parameter of every Moments API request, not in a header.

> **Caution**
>
> Never hardcode your API key directly in your app’s source code or commit it to version control. Store it securely using platform-specific tools like environment variables, encrypted storage, or secrets managers (e.g., Android Keystore, iOS Keychain, or dotenv for React Native).

- [Learn more about how to obtain your API key.](https://docs.momentscience.com/get-started/api-key)

## Step 2. Call the Moments API 

There are two common ways to call the Moments API, depending on your app architecture:

### Option A: Direct Call from the App

Make the HTTP request from the client. Include all required headers

### Option B: Proxy Through Your Backend 

Send a request from your app to your backend. Then, have your backend forward the request to the Moments API and relay the response to your app.

### Try it Out

Send a live request and see the response. Paste your API key into api\_key in the console below, adjust the body if you like, and click Try it. The result shows in the Responses panel on the right.

### Fetch Offers (Moments API)

`https://api.adspostx.com/native/v4/offers.json`

Returns personalized offers for one user. Paste your API key into api_key, adjust the body if you like, then click Try it.

#### Query Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `api_key` | `string` | Yes | Your API key with the Ads/Offers permission, from Profile Settings > API Keys in the dashboard. |
| `loyaltyboost` | `string` | No | Controls LoyaltyBoost offers. 0 excludes them, 1 includes them if available, 2 returns only LoyaltyBoost offers. |
| `creative` | `string` | No | Set to 1 to return only offers that have at least one image. |
| `campaignId` | `string` | No | Return offers from one campaign only. |

#### Body Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `placement` | `string` | Yes | Where the offer is shown, for example checkout_confirmation_page. |
| `ua` | `string` | No | The end user's User-Agent. If you call from a server, pass through the user's User-Agent. |
| `ip` | `string` | No | The end user's IP address, used for geo-targeting. |
| `adpx_fp` | `string` | No | A persistent, anonymous user ID. Strongly recommended, it enables frequency capping and opt-out handling. |
| `pub_user_id` | `string` | No | A unique, non-PII user ID. Required for PerksWallet-as-a-Service and User Selected Perks. |
| `dev` | `string` | No | Set to 1 to return test offers. Ignores geo restrictions and disables tracking. |

#### Request Examples

### cURL

```bash
curl --request POST \
     --url 'https://api.adspostx.com/native/v4/offers.json?api_key=string' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '{
     "placement": "string"
     }'
```

### Node.js

```javascript
var request = require('request');
var options = {
   'method': 'POST',
   'url': 'https://api.adspostx.com/native/v4/offers.json?api_key=string',
   'headers': {
      'accept': 'application/json',
      'content-type': 'application/json'
   },
   body: JSON.stringify({
      "placement": "string"
   })

};
request(options, function (error, response) {
   if (error) throw new Error(error);
   console.log(response.body);
});
```

### JavaScript

```javascript
var myHeaders = new Headers();
myHeaders.append("accept", "application/json");
myHeaders.append("content-type", "application/json");

var raw = JSON.stringify({
   "placement": "string"
});

var requestOptions = {
   method: 'POST',
   headers: myHeaders,
   body: raw,
   redirect: 'follow'
};

fetch("https://api.adspostx.com/native/v4/offers.json?api_key=string", requestOptions)
   .then(response => response.text())
   .then(result => console.log(result))
   .catch(error => console.log('error', error));
```

### Python

```python
import requests
import json

url = "https://api.adspostx.com/native/v4/offers.json?api_key=string"

payload = json.dumps({
   "placement": "string"
})
headers = {
   'accept': 'application/json',
   'content-type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

### Ruby

```ruby
require "uri"
require "json"
require "net/http"

url = URI("https://api.adspostx.com/native/v4/offers.json?api_key=string")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["accept"] = "application/json"
request["content-type"] = "application/json"
request.body = JSON.dump({
   "placement": "string"
})

response = https.request(request)
puts response.read_body
```

#### Sample Responses

### HTTP 200

```json
{
  "data": {
    "session_id": "abc123-def456-ghi789",
    "offers": [
      {
        "id": 12345,
        "campaign_id": 67890,
        "advertiser_name": "Premium Sports Store",
        "title": "Get 25% off athletic wear + free shipping",
        "description": "Save on top-brand athletic wear, running shoes, and gym equipment.",
        "click_url": "https://offers.momentscience.com/click/abc123",
        "cta_yes": "Shop Now",
        "cta_no": "No Thanks",
        "image": "https://cdn.momentscience.com/creatives/sports-banner.jpg",
        "pixel": "https://tracking.momentscience.com/impression/abc123",
        "beacons": {
          "close": "https://tracking.momentscience.com/close/abc123",
          "no_thanks_click": "https://tracking.momentscience.com/decline/abc123"
        }
      }
    ],
    "count": 1
  }
}
```

### HTTP 404

```json
{
  "message": "Ain't no cake like that."
}
```


- [Learn more about MomentPerks API](https://docs.momentscience.com/api-resources/momentperks-api)

## Step 3: Parse the API Response

The Moments API returns a list of eligible offers in the `data.offers[]` array. Each offer contains all the data needed to render the unit, handle user interactions, and track performance. At a minimum, your integration should extract and use the title, image, CTA, click URL, impression pixel, and optional beacons.

> **Tip**
>
> For more information about each parameter, please refer to the [MomentPerks API](https://docs.momentscience.com/api-resources/momentperks-api#body-parameters)

### Understanding Offer Anatomy

Each offer object in `data.offers[]` contains reusable fields for rendering offer units (e.g., Single Offer Unit or Multi Offer Unit). Here's a quick reference to the most important ones:

> **Tip**
>
> For a full explanation of all response fields and display guidance, refer to the [Offer Anatomy](https://docs.momentscience.com/get-started/offer-anatomy)

| **Field**                          | **Description**                                                                      |
| ---------------------------------- | ------------------------------------------------------------------------------------ |
| `offers[].title`                   | Main headline text. Use short\_headline for compact layouts.                         |
| `offers[].description`             | Primary offer copy. Use short\_description for limited-space formats.                |
| `offers[].image`                   | Main image URL for the offer.                                                        |
| `offers[].click_url`               | URL to open when the user taps the positive CTA (label from cta\_yes).               |
| `offers[].cta_yes`                 | Label for the primary action (e.g., "Claim Now").                                    |
| `offers[].cta_no`                  | Label for the negative action (e.g., "No Thanks").                                   |
| `offers[].terms_and_conditions`    | HTML-formatted terms. Render as HTML if present.                                     |
| `offers[].pixel`                   | Impression tracking URL. Fire once when the offer becomes visible.                   |
| `offers[].adv_pixel_url`           | Optional advertiser tracking pixel. Fire if provided.                                |
| `offers[].offerwall_url`           | URL to launch Perkswall for selected offer.                                          |
| `offers[].beacons.close`           | Track when the user closes the offer unit.                                           |
| `offers[].beacons.no_thanks_click` | Track when the user clicks the "No Thanks" button.                                   |
| `creatives[]`                      | Optional array of additional creative assets, including dimensions and types.        |
| `settings.offerwall_url`           | (Optional) URL to launch Perkswall. Button label comes from settings.offerwall\_cta. |

> **Note**
>
> You are not limited to a specific layout. These fields support custom implementations, feel free to build the UI that best fits your app's experience.

## Step 4: Trigger Impression Beacons 

Each offer returned by the [MomentPerks API](https://docs.momentscience.com/api-resources/momentperks-api)  includes impression and interaction tracking URLs. These must be implemented to ensure proper reporting, advertiser compliance, and offer optimization.

**Required Actions**

- **Trigger Impression Beacon:** Fire a successful `GET`request to `offers[].pixel` when the offer is displayed.
- **(If available) Trigger Advertiser Beacon: ** Fire a `GET`request to `offers[].adv_pixel_url` to satisfy advertiser tracking.
- **Display Terms and Conditions:** Render the offers\[].terms\_and\_conditions field as HTML to show offer-specific rules. If the field is empty, no terms apply.

### Additional Tracking

The following additional beacons and requirements are documented in the [MomentPerks Integration Checklist](https://docs.momentscience.com/products/momentperks/checklist) .

- **`offers[].beacons.close`: **&#x54;rigger when the user closes an offer unit.
- **`offers[].beacons.no_thanks_click`:** Trigger when the user opts out of an offer.
- **`adpx_fp` attribute:** Use to identify unique users for frequency control and reward tracking.
- **IP and User-Agent headers:** Required when proxying requests to ensure valid targeting.
- **LoyaltyBoost Support**: Special implementation required for rewarded offers, including postbacks, loyalty identifiers, and payout handling.

> **Tip**
>
> For more information about the required parameters when calling the Moments API, please refer to the [MomentPerks Integration Checklist](https://docs.momentscience.com/products/momentperks/checklist)

***

# Further Recommendations

## Configure Moments Settings in the Dashboard

The number of Offers returned in the Moments API response can be configured in the MomentScience dashboard.

**To configure offer count:**

1.
   Go to Settings -> [Configuration](https://app.momentscience.com/account/settings/behavior/).
2. Locate the "Number of Offers" setting.
3. Set your desired value.
4. Press Save Configuration.

This setting limits how many offers the Moments API returns in each response.

## Implement Postbacks for Conversion Tracking

Postbacks let you receive real-time notifications when a user converts on an Offer. These are sent to your designated endpoint and help track performance, optimize targeting, and power LoyaltyBoost rewards (if applicable).

- [Learn more about Handling Postback Events](https://docs.momentscience.com/platform/targeting-delivery/postback-events)

***

📢 If you're running into any issues while going through the integration process, feel free to contact us at [help@momentscience.com](mailto:help@Momentscience.com)

Source: https://docs.momentscience.com/mobile-integrations/mobile-api/index.mdx
