본문 바로가기메인 메뉴 바로가기사이드 메뉴 바로가기

kakao developers

Related sites
  • Docs
  • Push Notification
  • REST API

사이드 메뉴

Kakao Map

Search

Push Notification

REST API

This document describes how to integrate Push Notification APIs into your service with a REST API.

Requirements

  • You can register, retrieve, or revoke push tokens using the Android and iOS SDKs. However, to send push notifications, you must use a REST API.
  • You must register your Apple Push Notification service (APNs) or Firebase Cloud Messaging (FCM) authentication information on the app management page in advance. To see how to get and register authentication information, refer to Prerequisites.
  • You must receive a push token from APNs or FCM beforehand by referring to documentation that APNs and FCM provides.

Push notification API upgrade from v1 to v2

  • Effective date: December 2, 2020

  • Changes: As Google Cloud Messaging(GCM) has been replaced by Firebase Cloud Messaging (FCM), the value of push_type has been changed.

Register push token

Basic information
MethodURLAuthorization
POSThttps://kapi.kakao.com/v2/push/registerService app admin key

Registers push tokens saved on the devices of receiving user, also referred as 'device token', on the Kakao platform before using the Push notification function.

To use this API, you need the app's Admin key and push tokens issued from APNs or FCM. Notice that you must call this API only from the server to avoid security risk because this API requires your app's Admin key.

Allowed IP Address

To enhance security when sending push notifications, you can limit IPs to call the Kakao APIs from by registering the allowed Server IP Address in [App] > [Advanced] > [Allowed IP Address] on the app management page. For more information, refer to Security: Allowed IP address.

Use a unique number(long type) assigned to each user for uuid. device_id is another unique value to identify user's devices. You can use this value to send a push notification to a specific device of a receiving user if the user is using multiple devices.

If the request is successful, an integer is returned with the HTTP status code 200. The integer indicates how many days later the push token expires. Because the expiration time is not refreshed automatically, you must re-register the push token for the user and device before the push token expires.

Request

Header
NameDescriptionRequired
AuthorizationAuthorization: KakaoAK ${SERVICE_APP_ADMIN_KEY}
Service app admin key as a type of user authentication.
O
Body
NameTypeDescriptionRequired
uuidStringA user's unique ID.
Only integers in the range of 1 to ((2^63)-1) are allowed.
O
device_idStringDevice's unique ID to identify a user's multiple devices.
Used to register or revoke a specific device's push token if a user has multiple devices.
For APNs, you can use the push token received from APNs because each iOS device has different push tokens.
For FCM, you need an algorithm to generate a device's unique ID.
O
push_typeStringPush server type.
apns or fcm.
O
push_tokenStringPush token issued from APNs (64 characters) or FCM.O

Response

Body
NameTypeDescription
NONEIntegerValidity period until the push token expires.
If the token is unlimited, -1 is returned.

Sample

Request
curl -v -X POST "https://kapi.kakao.com/v2/push/register" \
-H "Content-Type: application/x-www-form-urlencoded;charset=utf-8" \
-H "Authorization: KakaoAK ${SERVICE_APP_ADMIN_KEY}" \
-d "uuid=1234" \
-d "device_id=0f365b39-c33d-39be-bdfc-74aaf5534470" \
-d "push_type=fcm" \
--data-urlencode "push_token=APA91bEZ3fjwrKV2mxAFvZMC960zKBWBVffLErwZgFzsFnzzsxgi5lSQlq3zvzObZBe4OnbwkTZfMqV7_a6fF0AJNgUjt5Scpo2BTaHyLVlK54QmwIQBahUwJprKjj0YvF_rh8l7CTvl6TRxqlqO_NIwaoAcI0MssA"
Response
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json;charset=UTF-8
-1

Retrieve push token

Basic information
MethodURLAuthorization
GET/POSThttps://kapi.kakao.com/v2/push/tokensService app admin key

Retrieves users' push tokens (device token) registered in the Kakao Push service.

When you request to retrieve push tokens, you must include either uuid or uuids in your request. If you want to retrieve the push tokens of a specific user, use uuid. To retrieve the push tokens of multiple users, use uuids. You must send a GET or POST request using the app's Admin key from the server.

Because the Kakao Push service supports multi-devices, a user may have multiple devices, and multiple device tokens may be registered for the user. If the request is successful, the push token information is returned as a JSON Array. Each push token includes information, such as a user's unique ID, a device's unique ID, the push token and its type, and the date and time when a push token has been created and updated.

Request

Header
NameDescriptionRequired
AuthorizationAuthorization: KakaoAK ${SERVICE_APP_ADMIN_KEY}
Service app admin key as a type of user authentication.
O
Query parameter
NameTypeDescriptionRequired
uuidStringA user's unique ID.
Only integers in the range of 1 to ((2^63)-1) are allowed.
O*
uuidsString[]List of uuids.
Up to 100 uuids are allowed.
O*
* To retrieve the push tokens of a specific user, pass 'uuid' as a required parameter. To retrieve push tokens of multiple users, pass 'uuids' as a required parameter.

Response

Body
NameTypeDescription
uuidStringA user's unique ID.
Only integers in the range of 1 to ((2^63)-1) are allowed.

Note: user_id has been deprecated and replaced with uuid.
device_idStringDevice's unique ID to identify a user's multiple devices.
push_typeStringPush server type.
apns or fcm.
push_tokenStringPush token issued from APNs (64 characters) or FCM.
created_atDatetimeThe time when the push token was registered.
updated_atDatetimeThe time when the push token was updated.
Parameter name change

user_id, one of the request parameters for the Retrieving push token API, has been replaced with uuid to have the same name as the parameter of other Push APIs. user_id will be deprecated after a certain period of time.

Sample

Request: Using uuid
curl -v -G GET "https://kapi.kakao.com/v2/push/tokens?uuid=1234" \
-H "Authorization: KakaoAK ${SERVICE_APP_ADMIN_KEY}"
Request: Using uuids
curl -v -X POST "https://kapi.kakao.com/v2/push/tokens" \
-H "Content-Type: application/x-www-form-urlencoded;charset=utf-8" \
-H "Authorization: KakaoAK ${SERVICE_APP_ADMIN_KEY}" \
--data-urlencode 'uuids=["1234", "5678"]'
Response
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
[
{
"uuid":"9876543211234",
"device_id":"0f365b39-c33d-39be-bdfc-74aaf5534470",
"push_type":"fcm",
"push_token":"APA91bEZ3fjwrKV2mxAFvZMC960zKBWBVffLErwZgFzsFnzzsxgi5lSQlq3zvzObZBe4OnbwkTZfMqV7_a6fF0AJNgUjt5Scpo2BTaHyLVlK54QmwIQBahUwJprKjj0YvF_rh8l7CTvl6TRxqlqO_NIwaoAcI0MssA",
"created_at":"2014-07-29T06:24:12Z",
"updated_at":"2014-07-29T06:24:12Z"
}
]

Delete push token

Basic information
MethodURLAuthorization
POSThttps://kapi.kakao.com/v2/push/deregisterService app admin key

Revokes a push token of a specific user or device.

You can call this API when a user wants to disable the push notification function or when a user logs out from a specific device. If a user has multiple devices, you can delete a specific device's push token by specifying the device ID.

If you pass uuid in your request, all push tokens registered for the user are deleted. To delete the user's specific device, include device_id along uuid in your request. You can also specify a push server type to delete by specifying push_type.

If the request is successful, an empty value is returned with the HTTP status code 200.

Request

Header
NameDescriptionRequired
AuthorizationAuthorization: KakaoAK ${SERVICE_APP_ADMIN_KEY}
Service app admin key as a type of user authentication.
O
Body
NameTypeDescriptionRequired
uuidLongA user's unique ID.
Only integers in the range of 1 to ((2^63)-1) are allowed.
O
device_idStringDevice's unique ID to identify a user's multiple devices.
Used to revoke a specific device's push token if a user has multiple devices.
For APNs, you can use the push token received from APNs because each iOS device has different push tokens.
For FCM, you need an algorithm to generate a device's unique ID.
X
push_typeStringPush server type.
apns or fcm.
X

Sample

Request
curl -v -X POST "https://kapi.kakao.com/v2/push/deregister" \
-H "Content-Type: application/x-www-form-urlencoded;charset=utf-8" \
-H "Authorization: KakaoAK ${SERVICE_APP_ADMIN_KEY}" \
-d "uuid=1234" \
-d "device_id=0f365b39-c33d-39be-bdfc-74aaf5534470" \
-d "push_type=fcm"
Response
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: application/json;charset=UTF-8

Send push notifications

Basic information
MethodURLAuthorization
POSThttps://kapi.kakao.com/v2/push/sendService app admin key

Sends push notifications to all devices registered as the receiving user's unique ID (uuid).

When you request to send push notifications, add payload that cotains the content of the push notification through the push_message parameter to the request. For this parameter, define PushMsgJson in JSON format by including for_apns or for_fcm according to the push server type. If you send push notifications to both platforms, you must include both for_apns and for_fcm. Because the configuration is slightly different for each platform, refer to the parameter descriptions as below.

If the request is successful, an empty value is returned with the HTTP status code 200. Note that this success status code does not guarantee that the push notification has been successfully sent to the device. If the APNs and FCM servers are unstable, push notifications may not be sent properly.

If failed, the failure information is passed to the return_url you specified in the request. The failure information includes uuid that the push notification is not delivered to, push token information and time of failure. In the case of FCM, a new push token value to refresh a push token may be returned as well.

APNs payload size limit

APNs only allows a push notification with a data length of 4 KB or less, excluding topic, push_alert, return_url, and push_token. For iOS 7 or less, up to 256 bytes are allowed. For VoIP notification, the maximum size is 5 KB.

If the payload size exceeds 4 KB and the message is a string type, cut off the last part of a message, and add ".." to the end of the message content.

Utilize format in app bundle

To downsize or customize a message, you can store a format for a specific push notification message in the app in advance and pass only the keys and parameters according to the specified format in your request. Refer to Creating the Remote Notification Payload.

You can use the Localized Formatted String function as follows:

  1. Define a format in JSON format in your app.
  2. Set loc-key to COMMENT_ALERT_FORMAT, and pass the values to be actually used in the message when requesting to send a push notification.
{
"message": {
"loc-key": "COMMENT_ALERT_FORMAT",
"loc-args": ["John", "2"]
}
}

When you have defined a format like this,

%@ users including %@ left comments.

The actual push notification is sent as follows.

2 friends including John left comments.

Request

Header
NameDescriptionRequired
AuthorizationAuthorization: KakaoAK ${SERVICE_APP_ADMIN_KEY}
Service app admin key as a type of user authentication.
O
Body
NameTypeDescriptionRequired
uuidsString[]List of user's unique ID(uuid).
Up to 100 uuids are allowed.
O
push_messagePushMsgJsonParameters to configure a message.
If you do not have any parameter to pass, send empty brackets().
Refer to PushMsgJson below.
O
bypassBooleanWhether to bypass when using the push notification function.
Used when managing push tokens manually in the service server, instead of registering the token on the Kakao platform.
(Default: false)
If set to true, you must include payload in PushMsgJson.
X
Bypass parameter

If you want to manage push tokens in the service server on your own, not registering them on the Kakao platform, use the bypass parameter. You must make a request to send a notification by passing the push token as the value of push_message. If any push token information is not passed, the request fails.

PushMsgJson: for_apns
NameTypeDescriptionSampleRequired
topicStringUsed when using VoIP (Voice over Internet Protocol)."voip"X
mutable-contentIntegerSet mutable-content parameters for APNs.1X
expirationIntegerTime to retry to send a push notification in seconds when a push notification is not available to receive.86400X
collapseStringPush message separator.
If multiple push notifications have the same value, only the last notification is sent to the user's device.
"we345"X
badgeIntegerNumber of badges to be displayed in the app on iOS device.123X
soundStringNotification sound when receiving push notifications."default"X
push_alertBooleanUsed when you want to have the device volume muted, send a push notification that does not appear in the notification center, or change the number of badges without sound or notification.falseX
content-availableIntegerIndicates that new content is available.1X
categoryStringSet an action to be shown in the notification center.INVITE_CATEGORYX
messageString or JsonThe content to be displayed in Notification Center as an alert."2 friends including John left comments."X
custom_fieldDictionaryUsed when you want to pass additional information to the app along with a message.{"article_id" : 111}X
return_urlStringUsed when you need to handle errors, such as "BadDeviceToken", "Unregistered", and "DeviceTokenNotForTopic" that occur when routing push notification.https://example.com/
fcm_push_fail
X
push_tokenStringPush token to be managed manually in the service server, not registering the token on the Kakao platform."AAABBBCCCDDD"X
apns_envStringAPNs server to send a push notification to.
sandbox or production.
(Default: production)
"sandbox"X
thread-idStringApp identifier to group notifications by relevance."Group01"X
apns-push-typeStringContents of payload.
Required in watchOS 6 or higher.
"alert"X
apns-priorityIntegerNotification priorities.
(Default: 10)
5X
target-content-idStringIdentifier used to target a window to bring to the front when opening a notification."Target01"X
interruption-levelStringImportance and delivery timing of notifications."time-sensitive"X
relevance-scoreDoubleRelevance score from 0 to 1.
Used to sort app's notifications in a system.
0.34X
PushMsgJson: for_fcm
NameTypeDescriptionSampleRequired
collapseStringPush message separator.
If multiple push notifications have the same value, only the last notification is sent to the user's device.
"wi10ck48"X
time_to_liveIntegerPeriod to store unsent messages in FCM storage in seconds.17200X
dry_runBooleanUsed for testing.
Not sent to the actual device.
true or falseX
priorityStringIf set to high, a push notification is sent to a user's device even in the Doze mode.
(Default: normal)
high or normalX
custom_fieldJsonUsed when you want to pass additional information to the app along with a message.
Unlike APNs, the total length of the custom_field per push notification is limited to 4 KB.
{"article_id" : 111 }X
notificationJsonKey-value pairs of predefined notification payload displayed to the user.
Refer to Table 2a, 2b or 2c under Notification payload support in Firebase Cloud Messaging HTTP protocol.
{"body":"great match!",
"title":"Portugal vs. Denmark",
"icon":"myicon"}
X
return_urlStringUsed when you need to handle errors that occur when routing push notification.https://example.com/
fcm_push_fail
X
push_tokenStringPush token to be managed manually in the service server, not registering the token on the Kakao platform."AAABBBCCCDDD"X

Response

Body: If fail to send a push notification through APNs
NameTypeDescription
userIdStringuuid (OLD: user_id) that owns the push token failed to send a push notification.
pushTokenStringPush token failed to send a push notification.
dateLongTime when sending a push notification failed.
In Unix timestamp format (unit: milliseconds).
Body: If fail to send a push notification through FCM
NameTypeDescription
userIdStringuuid (OLD: user_id) that owns the push token failed to send a push notification.
pushTokenStringPush token failed to send a push notification.
dateLongTime when sending a push notification failed.
In Unix timestamp format (unit: milliseconds).
newPushTokenStringOnly returned when bypassing.
A new push token used to refresh the push token stored under the designated uuid (user_id) when managing push tokens manually in the service server.

Sample

Request
curl -v -X POST "https://kapi.kakao.com/v2/push/send" \
-H "Content-Type: application/x-www-form-urlencoded;charset=utf-8" \
-H "Authorization: KakaoAK ${SERVICE_APP_ADMIN_KEY}" \
-d 'uuids=["1234", "5678"]' \
--data-urlencode 'push_message={
"for_apns":{
"badge":3,
"sound":"sound_file",
"push_alert":true,
"message":"2 friends including John left comments..",
"custom_field":{
"article_id":"111",
"comment_id":"222"
}
},
"for_fcm":{
"collapse": "articleId123",
"delay_while_idle":false,
"custom_field": {
"article_id": 111,
"comment_id": 222,
"comment_preview": "How have you been? ...(omitted)"
}
}
}'
PushMsgJson
{
"for_apns": {
"badge": 3,
"sound": "sound_file",
"push_alert": true,
"content-available": 1,
"category": "INVITE_CATEGORY",
"message": "2 friends including John left comments..",
"custom_field": {
"article_id": "111",
"comment_id": "222"
}
},
"for_fcm": {
"collapse": "articleId123",
"delay_while_idle": false,
"time_to_live": 17200,
"dry_run": false,
"priority": "high",
"custom_field": {
"article_id": 111,
"comment_id": 222,
"comment_preview": "How have you been? ...(omitted)"
}
}
}
Response: Succeess
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: application/json;charset=UTF-8
Response: Fail to send a push notification through APNs
POST /fcm_push_fail HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
userId=123&pushToken=abcdefg&date=1396582208000
Response: Fail to send a push notification through FCM
POST /fcm_push_fail HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
userId=123&pushToken=abcdefg&date=1396582208000&newPushToken=AAbbccddee

See more

Was this helpful?