Send a notification to a recipient (v2)
Purpose
Sends a notification to a given recipient_key or a token.
If you do not want to register a recipient first, you have the option of
sending it just to token you provide.
URL
Sandbox
https://sandbox.httpush.com/ACCOUNT_KEY/v2/recipient/notification.json
https://sandbox.httpush.com/ACCOUNT_KEY/v2/recipient/notification.xml
Production
https://production.httpush.com/ACCOUNT_KEY/v2/recipient/notification.json
https://production.httpush.com/ACCOUNT_KEY/v2/recipient/notification.xml
Find your ACCOUNT_KEY on
the dashboard at the management web site.
HTTP Method
POST
Formats
JSON, XML
Requires Authentication
Yes (about Authentication)
Parameters
Send the parameters as either JSON or XML data as the body of your request.
a: The application_hash. Provided by the management site. Identifies under which application the recipient should be created.r: A recipient_key (an application wide unique identifier for a given recipient). Can be anything you want but you should hash the recipient_key to make its encoding save for the web. You should use a SHA-1 hash on the recipient_key. The max. length is 128 characters. The recipient_key should be unique.t: A token provided by the Apple Push Notification service-
b: Have a look at the documentation provided by Apple, to learn how the payload should be formated, basically it is:
{"aps":{"badge":1,"alert":"Hi from the API"}}
h2. Usage Notes
- Send either a
recipient_keyor a token. recipient_keystrings should be URL encoded.json_body isnot allowed to be larger than 256 byte.
Example JSON data
{"a": "05673b6d12c796afc0cb74849e60573949bf2521", "b": "{\"aps\":{\"badge\":1,\"alert\":\"Hi from squidshot!\"}}", "r": "test"}
{"a": "05673b6d12c796afc0cb74849e60573949bf2521", "b": "{\"aps\":{\"badge\":1,\"alert\":\"Hi from squidshot!\"}}", "t": "1ab182418e3bca321dab504f96dd0339869eef0c"}
Example XML data
<?xml version="1.0" encoding="UTF-8"?> <notification> <a>05673b6d12c796afc0cb74849e60573949bf2521</a> <b>{"aps":{"badge":1,"alert":"Hi from squidshot!"}}</b> <r>test</r> </notification>
<?xml version="1.0" encoding="UTF-8"?> <notification> <a>05673b6d12c796afc0cb74849e60573949bf2521</a> <b>{"aps":{"badge":1,"alert":"Hi from squidshot!"}}</b> <t>1ab182418e3bca321dab504f96dd0339869eef0c</t> </notification>
Responses
See return codes for all codes, here are specific ones
400 {"error" : "error parsing the json input"}
400 {"error" : "application_hash missing in notification"}
400 {"error" : "json body is missing in notification"}
400 {"error" : "recipient missing in notification"}
400 {"error" : "recipient not found"}
400 {"error" : "application_hash not found"}
400 {"error" : "no apns token set registered for recipient"}
XML returns the same errors string like JSON.
<?xml version="1.0" encoding="UTF-8"?> <errors> <error>application_hash has wrong length</error> </errors>
Usage examples
cURL (about cURL)
curl -k -X POST -d '{"a": "05673b6d12c796afc0cb74849e60573949bf2521", "b": "{\"aps":{\"badge\":1,\"alert\":"Hi from squidshot!\"}}", "r": "test"}' -u 'c3bb3b10864278055b3873503629904b98862895:1ab182418e3bca321dab504f96dd0339869eef0c' https://sandbox.httpush.com/ACCOUNT_KEY/v2/recipient/notification.json
curl -k -X POST -d '{"a": "05673b6d12c796afc0cb74849e60573949bf2521", "b": "{\"aps\":{\"badge\":1,\"alert\":\"Hi from squidshot!\"}}", "t": "1ab182418e3bca321dab504f96dd0339869eef0c"}' -u 'c3bb3b10864278055b3873503629904b98862895:1ab182418e3bca321dab504f96dd0339869eef0c' https://sandbox.httpush.com/ACCOUNT_KEY/v2/recipient/notification.json
curl -k -X POST -d '<?xml version="1.0" encoding="UTF-8"?><notification><a>05673b6d12c796afc0cb74849e60573949bf2521</a><b>{"aps":{"badge":1,"alert":"Hi from squidshot!"}}</b><r>test</r></notification>' -u 'c3bb3b10864278055b3873503629904b98862895:1ab182418e3bca321dab504f96dd0339869eef0c' https://sandbox.httpush.com/ACCOUNT_KEY/v2/recipient/notification.xml
curl -k -X POST -d '<?xml version="1.0" encoding="UTF-8"?><notification><a>05673b6d12c796afc0cb74849e60573949bf2521</a><b>{"aps":{"badge":1,"alert":"Hi from squidshot!"}}</b><t>1ab182418e3bca321dab504f96dd0339869eef0c</t></notification>' -u 'c3bb3b10864278055b3873503629904b98862895:1ab182418e3bca321dab504f96dd0339869eef0c' https://sandbox.httpush.com/ACCOUNT_KEY/v2/recipient/notification.xml
Do you have an example to share in the language of your choice? Please share!