How to send push notification with custom data?


#1

We need to send the push notification with custom data. Currently we are using push.json API. So, We need JSON structure or way of achieve the Push notification with custom data by using API.


#2

Hey @Naveen_L,

The structure to send push notification is as follows. In the below payload, you can define your own custom set of data or send on the basis of an identity. The “content” field will contain the message that needs to be sent out.

1.) Create campaigns:

  {
    "name": "My API Campaign",
    "estimate_only": true,
    "target_mode":"push",
    "where": {
        "event_name": "App Launched",
        "from": 20150101,
        "to": 20150303,
        "common_profile_properties": {
            "profile_fields": [
                {
                    "name": "Customer Type",
                    "operator":"equals",
                    "value": "Platinum"
                }
            ]
        }
    },
    "respect_frequency_caps": false,
    "content": {
        "title": "Hi!",
        "body": "How are you doing today?",
        "platform_specific": {
            "windows": {
                "deep_link": "example.com",
                "Key": "Value_windows"
            },
            "ios": {
                "mutable-content": "true", 
                "deep_link": "example.com",
                "sound_file": "example.caf",
                "category": "application category//Books",
                "badge_count": 1,
                "Key": "Value_ios"
            },
            "android": {
                "background_image": "http://example.jpg",
                "default_sound": true,
                "deep_link": "example.com",
                "large_icon": "http://example.png",
                "Key": "Value_android",
                "ttl":24 
            }
        }
    },
    "devices": [
        "android",
        "ios",
        "windows"
    ],
    "when": "now"
}

Link: https://developer.clevertap.com/docs/create-campaign-api#section-create-campaign-api-target-user-events-properties

2.) To send push notifications on the basis of identity:

{
    "to": {
        "FBID": [
            "102029292929388",
            "114342342453463"
        ],
        "GPID": [
            "1928288389299292"
        ],
        "Email": [
            "john@doe.com",
            "jane@doe.com"
        ],
        "Identity": [
            "JohnDoe"
        ],
        "objectId": [
            "_asdnkansdjknaskdjnasjkndja",
            "-adffajjdfoaiaefiohnefwprjf"
        ]
    },
    "tag_group": "my tag group",
    "respect_frequency_caps": false,
    "content": {
        "title": "Welcome",
        "body": "Hello world!",
        "platform_specific": {
            "windows": {
                "deep_link": "example.com",
                "key": "value_windows"
            },
            "ios": {
                "deep_link": "example.com",
                "sound_file": "example.caf",
                "category": "notification category",
                "badge_count": 1,
                "key": "value_ios"
            },
            "android": {
                "background_image": "http://example.jpg",
                "default_sound": true,
                "deep_link": "example.com",
                "large_icon": "http://example.png",
                "key": "value_android"
            }
        }
    }
}

Link: https://developer.clevertap.com/docs/create-campaign-api#section-create-campaign-api-target-users-by-their-identities

Best,
Suvidhi