Direct send

Sends a notification directly to a device handle (a valid token as expressed by the Notification type). Users of this API do not need to use registrations or installations. Instead, you manage all devices on their own and use Azure Notification Hubs solely as a pass-through service to communicate with the various Push Notification Services.

Important

Firebase Cloud Messaging (FCM) is a service that, among other things, facilitates developers sending push notifications to Google Play-supported Android devices. Azure Notification Hubs currently communicates with FCM using the legacy HTTP protocol. FCM v1 is an updated API that offers more features and capabilities. Google announced that they are deprecating FCM legacy HTTP and will stop supporting it on June 20, 2024. Therefore, developers who use Azure Notification Hubs to communicate with Google Play-supported Android devices today, will need to migrate their applications and notification payloads to the newer format. Azure Notification Hubs will continue to support FCM legacy HTTP until Google stops accepting requests. Once the new FCM integration is complete, Azure Notification Hubs will announce when you can begin migrating. For more details, see the migration steps in the this article.

Request

Method Request URI HTTP Version
POST https://{namespace}.servicebus.windows.net/{NotificationHub}/messages/?direct&api-version=2015-04 HTTP/1.1

Request headers

The following table describes required and optional request headers.

Request header Description
Authorization SAS token generated as specified in Shared Access Signature Authentication with Service Bus.
Content-Type Set the Content-Type header based on the target platform notification service:
  • WNS: Set to application/json;charset=utf-8 or application/xml. If the notification type (X-WNS-Type) is "wns/raw", set to application/octet-stream.
  • GCM and APNS: Set to application/json;charset=utf-8.
  • MPNS: Set to application/xml;charset=utf-8.
ServiceBusNotification-DeviceHandle The PNS device handle.
ServiceBusNotification-Tags {single tag identifier} (optional)
ServiceBusNotification-Format Set to one of the following valid PlatformType values: windows, apple, gcm, windowsphone, adm, nokiax, baidu
x-ms-version 2015-04 (Supported by 2015-01 and later)

Request body

Based on the platform type, the request body formats changes. Refer to the body formats for each individual platform in native Send REST APIs.

Response

The response includes an HTTP status code and a set of response headers. Response body is returned on success.

Response codes

Code Description
201 Message successfully sent.
400 The request is malformed (for example, not valid routing headers, not valid content-type, message exceeds size, bad message format).
401 Authorization failure. The access key was incorrect.
403 Quota exceeded or message too large; message was rejected.
404 No message branch at the URI.
413 Requested entity too large. The message size cannot be over 64 Kb.

For information about status codes, see Status and Error Codes.

Response headers

When using HTTP 1.1, PNS feedback does not work when using certificate-based authentication; it does not return any data. Use token-based authentication.

Response header Description
Content-Type application/xml; charset=utf-8
Location This header is only available for Standard tier Notification Hubs.

This header contains the notification message ID. It is used with per-message telemetry: Get Notification Message Telemetry and correlating PNS feedback. The location header uses the following format:

https://{your namespace}.servicebus.windows.net/{your hub name}/messages/{notification message id}?api-version=2015-04.

Response body

None.

Next steps