# Integrating with APIs

### 1. Register Device/User

![](https://1004846827-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0ahLW2WavtwcwNbSR9%2F-MTFwgtkHaBkZVRZkIIt%2F-MTFwtvo8KcmvX71tjBH%2FProduct%20Flow%20Diagram%20-%20v2.0%20-%201.%20Device%20registration%20flow.jpg?alt=media\&token=084c04a4-8faa-429a-8558-2e2e59299c33)

The following API can be used to register as well as update the attributes of a user:

## Register a device

<mark style="color:green;">`POST`</mark> `https://api.customerglu.com/user/v1/user/sdk?token=true`

Every single user must first be registered with CustomerGlu to create segments, run campaigns and report.\
\
\
To register/update a device/user (Eg: Can be called during user sign up, app Install, firebase token refresh etc)\
\
Returns a JWT token in response\
\
The token needs to be passed in all the subsequent API calls\
\
**To be called on firebase/APNS token refresh to update the token. Custom user attributes can be registered/updated by using `customAttributes` object.**<br>

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| Content-Type | string | application/json |

#### Request Body

| Name                                       | Type   | Description                                         |
| ------------------------------------------ | ------ | --------------------------------------------------- |
| userId<mark style="color:red;">\*</mark>   | string |                                                     |
| writeKey<mark style="color:red;">\*</mark> | string | Write key provided by CustomerGlu                   |
| anonymousId                                | string |                                                     |
| userName                                   | string |                                                     |
| email                                      | string |                                                     |
| phone                                      | string |                                                     |
| deviceId                                   | string |                                                     |
| deviceType                                 | string | Accepted values: android/ios/default                |
| deviceName                                 | string |                                                     |
| firebaseToken                              | string | Firebase token for enabling push notification       |
| cookieId                                   | string |                                                     |
| appVersion                                 | string |                                                     |
| referredBy                                 | string | Id of the referred user (referral programs)         |
| customAttributes                           | object | Custom key-value pair. Can be used for segmentation |
| profile                                    | object |                                                     |
| profile.age                                | string |                                                     |
| profile.city                               | string |                                                     |
| profile.country                            | string |                                                     |
| profile.timezone                           | string |                                                     |
| identities                                 | object |                                                     |
| identities.facebook\_id                    | string |                                                     |
| identities.google\_id                      | string |                                                     |
| identities.android\_id                     | string |                                                     |
| identities.ios\_id                         | string |                                                     |
| identities.clevertap\_id                   | string |                                                     |
| identities.mparticle\_d                    | string |                                                     |
| identities.segment\_id                     | string |                                                     |
| identities.moengage\_id                    | string |                                                     |
| apnsDeviceToken                            | string | APNS token for enabling push notification           |

{% tabs %}
{% tab title="200  Response successfully retrieved." %}

```
{
    "success": true,
    "data": {
        "user": {
            "id": "6022d697eb895132d430a803",
            "userId": "test2081",
            "gluId": "d6aeadf1-7131-4bb9-8c67-e3b003683b1f",
            "userName": "Test User 2077",
            "email": "testuser@customerglu.net",
            "phone": "977777252222",
            "cookieId": "asdhbfkjsdv",
            "appVersion": "1.0.3",
            "client": "c27ecb52-0f00-443e-8dfe-01585b426ca7",
            "referralLink": null,
            "referredBy": "testuser36",
            "customAttributes": {
                "guruLevel": 2
            },
            "profile": {
                "age": "29",
                "city": "Bangalore",
                "country": "India",
                "timezone": "America/Los_Angeles"
            },
            "identities": {
                "facebook_id": "asdf",
                "google_id": "asdf",
                "android_id": "asdf",
                "ios_id": "asdf",
                "clevertap_id": "asdfa",
                "mparticle_id": "asdfasdf",
                "segment_id": "asdf",
                "moengage_id": "asdf"
            },
            "sessionId": "tempSessionId",
            "deviceId": "xampT",
            "deviceType": "ios",
            "deviceName": "Samsung Note 07"
        },
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJ0ZXN0MjA4MSIsImdsdUlkIjoiZDZhZWFkZjEtNzEzMS00YmI5LThjNjctZTNiMDAzNjgzYjFmIiwiY2xpZW50IjoiYzI3ZWNiNTItMGYwMC00NDNlLThkZmUtMDE1ODViNDI2Y2E3IiwiZGV2aWNlSWQiOiJ4YW1wVCIsImRldmljZVR5cGUiOiJpb3MiLCJpYXQiOjE2MTI4OTU4OTUsImV4cCI6MTY0NDQzMTg5NX0.bzW0HWbeI1hAIJN1xuuP5y3zUkzlSWn7fn6lDMxb_eM"
    }
}

```

{% endtab %}
{% endtabs %}

### 2. Fetching all Campaigns and Wallet URLs

The following API can be used to fetch the wallet url, and the urls, status information of individual campaigns available for a user:

## Load Campaigns

<mark style="color:blue;">`GET`</mark> `https://api.customerglu.com/reward/v1.1/user`

To fetch all the ongoing campaigns that can be used to create banners or load the program UI using URLs.\
\
The response can be filtered using query params like:\
\
**status**: \[pristine, clicked, completed] \
**type**: \[memorygame, referral, slotmachine, spinthewheel, quiz, streak, multistep]\
\
Following properties from response object can be used based on the user story\
**defaultUrl**:  the URL for CustomerGlu wallet page which contains all the ongoing campaigns and rewards

#### Query Parameters

| Name   | Type   | Description                                                                                                   |
| ------ | ------ | ------------------------------------------------------------------------------------------------------------- |
| status | string | <p>values can be <br>\[pristine,clicked,completed,in-progress]</p>                                            |
| type   | string | values can be any of these \[spinthewheel,referral,quiz,slotmachine,memorygame,scratchcard, streak,multistep] |

#### Headers

| Name          | Type   | Description                                                             |
| ------------- | ------ | ----------------------------------------------------------------------- |
| Authorization | string | Bearer \<token> (jwt token retrieved from the response of Register API) |
| Content-Type  | string | application/json                                                        |

{% tabs %}
{% tab title="200 " %}

```
{
    "success": true,
    "defaultUrl": "https://customerglu-previews-2.vercel.app/quiz?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJ0ZXN0MjUiLCJjbGllbnQiOiIxN2E5MjNhMS04NGJjLTQwZTYtYWFiZi03YTNkZWE4Nzg0MDEiLCJkZXZpY2VJZCI6ImRldmljZWIiLCJkZXZpY2VUeXBlIjoiYW5kcm9pZCIsImlhdCI6MTYxMDU2MjY0MSwiZXhwIjoxNjQyMDk4NjQxfQ.XDVk0T7GoFgYozj9J17L7LdYtaJbjhpL1DOmF3VPWBw",
    "defaultBanner": {
        "liveCampaignCount": 2,
        "totalRewardCount": 0,
        "unplayedGamesCount": 1,
        "liveChallengeCount": 0
    },
    "campaigns": [
        {
            "campaignId": "3b6a9735-7255-4d38-b186-861b185d22a7",
            "url": "https://customerglu-xyz.com",
            "type": "quiz",
            "status": "clicked",
            "banner": {
                "title": "Food Trivia",
                "body": "Answer these questions based on cuisines from around the world to win rewards",
                "image": "https://customerglu.com/assets/food.png"
            }
        },
        {
            "campaignId": "8eaf889d-e806-4fef-953e-419f1c620ad8",
            "url": "https://customerglu-abc.com",
            "type": "activityProgram",
            "status": "in-progress",
            "banner": {
                "title": "First 100",
                "body": "Get $100 on completing all tasks.",
                "image": "https://customerglu.com/assets/first-100.png"
            }
        }
    ]
}
```

{% endtab %}
{% endtabs %}
