Web Push
Create the VAPID keys of a web application and send encrypted push notifications to the browsers that subscribed, with TTL, urgency and topic. Expired subscriptions are reported so they can be deleted. Typical uses: tell a customer that an order has shipped, alert a user in a web application.
webpush keyswebpush send

webpush keys


Description

    Create a VAPID key pair (ECDSA P-256): {public_key, private_key, curve}, both in base64url without padding: public_key is the uncompressed point of 65 bytes (applicationServerKey of the browser), private_key the 32 bytes of the secret, to put in an secret. A new pair at each call

admin
webpush keys
mentdb
{"public_key": "BDk5lM7xpZbilQxM0ATeLIzivSUZZ0a48oi91GHjvWt2GoFVEd21SC7ydySVUye1Tc_6NoQKcEMAVqQ9putI_Ms", "private_key": "wz9aJecaKeQkm56wOOeGsRfpDTeElvPABQXs92O_J-w", "curve": "P-256"}
Used in use cases (1 recipe)

    Web application developer › Create the VAPID keys of a web application for browser push notifications
Often used with

    not  ·  string length  ·  string substr

webpush send <subscription> <payload> <json_params>


Description

    Send one push message. Parameters: vapid_private_key (required), vapid_public_key (required), subject (required: mailto:you@example.org or an https URL, for the push service to contact you), ttl (seconds kept by the push service if the browser is off line: 86400, 0 to 2419200), urgency (very-low, low, normal or high), topic (1 to 32 letters, digits, - or _: a newer message with the same topic replaces the one not yet delivered), jwt_expiry_s (43200, 60 to 86400), known_services_only (false), timeout_ms (15000), dry_run (encrypts and gives the sizes, sends nothing). Result: {sent, status, host, ttl, payload_bytes, body_bytes, message_url}

Parameters

    subscription:   The JSON of the subscription of the browser: {"endpoint": "https://...", "keys": {"p256dh": "...", "auth": "..."}} - String - required
    payload:   The text of the message, often JSON for the service worker; empty for a push without data - String - required
    json_params:   The parameters - String - required
admin
webpush send "{\"endpoint\": \"http://127.0.0.1:37101/push/ok/sub-1\", \"keys\": {\"p256dh\": \"BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4\", \"auth\": \"BTBZMqHH6r4Tts7J_aSIgg\"}}" "{\"title\": \"Order 123 shipped\", \"url\": \"/orders/123\"}" "{\"vapid_private_key\": \"vapid_private_key\", \"vapid_public_key\": \"BFkjA2UBIjY-p-4-sgny-GEA3LnnUPMt-D3AXwdGfN_UXvvMgP8t23kQHRvlRsUxQVTLLHC_N5_Ae3d-SgcitNg\", \"subject\": \"mailto:ops@example.org\", \"ttl\": 3600, \"urgency\": \"high\", \"topic\": \"order-123\"}"
mentdb
{"sent": true, "status": 201, "host": "127.0.0.1:37101", "ttl": 3600, "payload_bytes": 52, "body_bytes": 155, "message_url": "http://127.0.0.1:37101/push/msg/1"}
Fixed result from a real call to a local fake of the service on 127.0.0.1 (the real service was not called): a push without data
admin
webpush send "{\"endpoint\": \"http://127.0.0.1:37101/push/ok/sub-1\", \"keys\": {\"p256dh\": \"BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4\", \"auth\": \"BTBZMqHH6r4Tts7J_aSIgg\"}}" "" "{\"vapid_private_key\": \"vapid_private_key\", \"vapid_public_key\": \"BFkjA2UBIjY-p-4-sgny-GEA3LnnUPMt-D3AXwdGfN_UXvvMgP8t23kQHRvlRsUxQVTLLHC_N5_Ae3d-SgcitNg\", \"subject\": \"mailto:ops@example.org\"}"
mentdb
{"sent": true, "status": 201, "host": "127.0.0.1:37101", "ttl": 86400, "payload_bytes": 0, "body_bytes": 0, "message_url": "http://127.0.0.1:37101/push/msg/1"}
Fixed result from a real call to a local fake of the service on 127.0.0.1 (the real service was not called): the subscription has expired
admin
webpush send "{\"endpoint\": \"http://127.0.0.1:37101/push/gone/sub-2\", \"keys\": {\"p256dh\": \"BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4\", \"auth\": \"BTBZMqHH6r4Tts7J_aSIgg\"}}" "x" "{\"vapid_private_key\": \"vapid_private_key\", \"vapid_public_key\": \"BFkjA2UBIjY-p-4-sgny-GEA3LnnUPMt-D3AXwdGfN_UXvvMgP8t23kQHRvlRsUxQVTLLHC_N5_Ae3d-SgcitNg\", \"subject\": \"mailto:ops@example.org\"}"
mentdb
Sorry, an error appears (webpush send: the subscription has expired or was cancelled (HTTP 410 from 127.0.0.1:37101): delete it and do not send to it again).
Fixed result from a real call to a local fake of the service on 127.0.0.1 (the real service was not called): dry_run
admin
webpush send "{\"endpoint\": \"http://127.0.0.1:37101/push/ok/sub-1\", \"keys\": {\"p256dh\": \"BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4\", \"auth\": \"BTBZMqHH6r4Tts7J_aSIgg\"}}" "Hello" "{\"vapid_private_key\": \"vapid_private_key\", \"vapid_public_key\": \"BFkjA2UBIjY-p-4-sgny-GEA3LnnUPMt-D3AXwdGfN_UXvvMgP8t23kQHRvlRsUxQVTLLHC_N5_Ae3d-SgcitNg\", \"subject\": \"mailto:ops@example.org\", \"dry_run\": true}"
mentdb
{"dry_run": true, "host": "127.0.0.1:37101", "ttl": 86400, "urgency": null, "topic": null, "payload_bytes": 5, "body_bytes": 108, "content_encoding": "aes128gcm"}
Without the private key
admin
webpush send "{\"endpoint\": \"http://127.0.0.1:37101/push/ok/sub-1\", \"keys\": {\"p256dh\": \"BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4\", \"auth\": \"BTBZMqHH6r4Tts7J_aSIgg\"}}" "x" "{\"vapid_public_key\": \"BFkjA2UBIjY-p-4-sgny-GEA3LnnUPMt-D3AXwdGfN_UXvvMgP8t23kQHRvlRsUxQVTLLHC_N5_Ae3d-SgcitNg\", \"subject\": \"mailto:ops@example.org\"}"
mentdb
ERROR: Sorry, an error appears (the parameter 'vapid_private_key' is required (the name of the secret, secret set)).