Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Curl the APNS http/2 API
# Note: You MUST have curl 7.47+ with http/2 support compiled in
curl -v \
-d '{"aps":{"alert":"<message>","badge":42}}' \
-H "apns-topic: <bundle id>" \
-H "apns-priority: 10" \
--http2 \
--cert <certificate file> \
https://api.development.push.apple.com/3/device/<device token>
@greencoder

This comment has been minimized.

Copy link
Owner Author

@greencoder greencoder commented May 11, 2016

This is only for testing - APNS requires a persistent connection to be maintained or you run the risk of being flagged as a denial of service attack.

@satheeshwaran

This comment has been minimized.

Copy link

@satheeshwaran satheeshwaran commented Aug 4, 2016

The only curl is working for me to send push to the new APNS provider via HTTP2, thank god I found this only after a day of trying and not breaking my head anymore.

@judepereira

This comment has been minimized.

Copy link

@judepereira judepereira commented Nov 2, 2016

Using the new, token based provider authentication:

curl -v 
     -d '{"aps":{"alert":"hello"}}'
     -H "apns-topic: <your app bundle ID>" 
     -H "authorization: bearer xxxx.yyyy.zzzz" 
     --http2
     https://api.push.apple.com/3/device/<device token>

You will need to generate your JWT token and sign it using ES256. This is out of scope here (it's easy to find many libraries on a quick Google search).

@hissain

This comment has been minimized.

Copy link

@hissain hissain commented Mar 19, 2020

I am getting below error for,

curl -v \
-d '{"aps":{"alert":"<message>","badge":42}}' \
-H "apns-topic: <bundle id>" \
-H "apns-priority: 10" \
--http2 \
--cert Certificate.p12 \
https://api.development.push.apple.com/3/device/<device token>

curl: (58) could not load PEM client certificate, LibreSSL error error:09FFF06C:PEM routines:CRYPTO_internal:no start line, (no key found, wrong pass phrase, or wrong file format?)

Any idea?

@Sephaq

This comment has been minimized.

Copy link

@Sephaq Sephaq commented Mar 25, 2020

I am getting below error for,

curl -v \
-d '{"aps":{"alert":"<message>","badge":42}}' \
-H "apns-topic: <bundle id>" \
-H "apns-priority: 10" \
--http2 \
--cert Certificate.p12 \
https://api.development.push.apple.com/3/device/<device token>

curl: (58) could not load PEM client certificate, LibreSSL error error:09FFF06C:PEM routines:CRYPTO_internal:no start line, (no key found, wrong pass phrase, or wrong file format?)

Any idea?

You're using a .p12 certificate, you need to use a .pem

@bzhoek

This comment has been minimized.

Copy link

@bzhoek bzhoek commented Jun 5, 2020

@hissain, you when you add --cert-type P12 it works, tested with curl 7.64.1 on macOS.

curl -v \
-d '{"aps":{"alert":"<message>","badge":42}}' \
-H "apns-topic: <bundle>" \
-H "apns-priority: 10" \
--http2 \
--cert-type P12 --cert Certificates.p12 \
https://api.development.push.apple.com/3/device/<token>
@hissain

This comment has been minimized.

Copy link

@hissain hissain commented Jun 5, 2020

@bzhoek
Thanks a lot. It worked.

@rahulvyas

This comment has been minimized.

Copy link

@rahulvyas rahulvyas commented Jul 28, 2020

Did anyone able to run feedback service from curl command ?

@mmgrt

This comment has been minimized.

Copy link

@mmgrt mmgrt commented Oct 1, 2020

@hissain, you when you add --cert-type P12 it works, tested with curl 7.64.1 on macOS.

curl -v \
-d '{"aps":{"alert":"<message>","badge":42}}' \
-H "apns-topic: <bundle>" \
-H "apns-priority: 10" \
--http2 \
--cert-type P12 --cert Certificates.p12 \
https://api.development.push.apple.com/3/device/<token>

Thank you!

For specifying the P12 certificate password:

 curl -v \
 -d '{"aps":{"alert":"<message>","badge":42}}' \
 -H "apns-topic: <bundle>" \
 -H "apns-priority: 10" \
 --http2 \
 --cert-type P12 --cert Certificates.p12:password \
 https://api.development.push.apple.com/3/device/<token>
@izagood

This comment has been minimized.

Copy link

@izagood izagood commented Jan 13, 2021

this is token base example

curl -v
     -H "apns-topic: com.example.MyApp"
     -H "authorization: bearer eyAia2lkIjogIjhZTDNHM1JSWDciIH0.eyAiaXNzIjogIkM4Nk5WOUpYM0QiLCAiaWF0IjogIjE0NTkxNDM1ODA2NTAiIH0.MEYCIQDzqyahmH1rz1s-LFNkylXEa2lZ_aOCX4daxxTZkVEGzwIhALvkClnx5m5eAT6Lxw7LZtEQcH6JENhJTMArwLf3sXwi"
     -H "apns-id : eabeae54-14a8-11e5-b60b-1697f925ec7b"
     -H "apns-push-type : alert"
     -H "apns-expiration  : 0"
     -H "apns-priority   : 10"
     --http2 --tlsv1.3 https://api.sandbox.push.apple.com/3/device/00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0
     -d "{"aps":{"alert":"hello"}}"
@Kenesg12

This comment has been minimized.

Copy link

@Kenesg12 Kenesg12 commented Mar 31, 2021

@izagood `

this is token base example

curl -v
     -H "apns-topic: com.example.MyApp"
     -H "authorization: bearer eyAia2lkIjogIjhZTDNHM1JSWDciIH0.eyAiaXNzIjogIkM4Nk5WOUpYM0QiLCAiaWF0IjogIjE0NTkxNDM1ODA2NTAiIH0.MEYCIQDzqyahmH1rz1s-LFNkylXEa2lZ_aOCX4daxxTZkVEGzwIhALvkClnx5m5eAT6Lxw7LZtEQcH6JENhJTMArwLf3sXwi"
     -H "apns-id : eabeae54-14a8-11e5-b60b-1697f925ec7b"
     -H "apns-push-type : alert"
     -H "apns-expiration  : 0"
     -H "apns-priority   : 10"
     --http2 --tlsv1.3 https://api.sandbox.push.apple.com/3/device/00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0
     -d "{"aps":{"alert":"hello"}}"

how you get authorization token?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment