Skip to main content

Send your first notification

Start with one device and a simple message. This makes it easier to distinguish registration problems from audience-selection or navigation problems.

Before you begin​

Have the AppKey and server-sending credential supplied by NextAppMarket, a registered device using that AppKey, and permission to display notifications on that device. Load JPUSH_APP_KEY, JPUSH_MASTER_SECRET, and JPUSH_REGISTRATION_ID into your server environment.

This example calls the JPush REST API directly from your backend. Complete the server-credential handoff with NextAppMarket if direct sending has not yet been provisioned.

Send the request​

The following Node.js example uses the built-in fetch API. Save it as an .mjs file and run it on your server:

const required = (name) => {
const value = process.env[name];
if (!value) throw new Error(`Missing ${name}`);
return value;
};

const appKey = required('JPUSH_APP_KEY');
const secret = required('JPUSH_MASTER_SECRET');
const registrationId = required('JPUSH_REGISTRATION_ID');
const credentials = Buffer.from(`${appKey}:${secret}`, 'utf8').toString('base64');

const response = await fetch('https://api.jpush.cn/v3/push', {
method: 'POST',
signal: AbortSignal.timeout(10000),
headers: {
Authorization: `Basic ${credentials}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
platform: ['android'],
audience: { registration_id: [registrationId] },
notification: {
android: {
alert: 'Your notification integration is ready.',
title: "NextAppMarket",
extras: { screen: 'notification_test', notification_id: 'test_001' },
},
},
options: { time_to_live: 300 },
}),
});

const result = await response.json();
if (!response.ok) {
throw new Error(`JPush request failed (${response.status}): ${result.error?.code ?? 'unknown'}`);
}
console.log({ msg_id: result.msg_id, sendno: result.sendno });

For iOS, set platform to ['ios'], replace the android notification with an ios object, and set the APNs option for the registered build:

{
"notification": {
"ios": {
"alert": "Your notification integration is ready.",
"sound": "default",
"extras": {"screen": "notification_test", "notification_id": "test_001"}
}
},
"options": {"time_to_live": 300, "apns_production": true}
}

This is an excerpt to merge into the request. Set apns_production to match the actual APNs environment; use false for an installation registered with development APNs.

Confirm the outcome​

Save msg_id with your own notification record. Check that the expected device displays the message, then tap it and confirm that your app opens safely. A successful HTTP response records API acceptance, not device display.

Handle failures deliberately​

Use the returned error code to correct credentials, targeting, or payload problems. Honor rate limits and avoid a tight retry loop. If a request times out after submission, record the uncertain send before retrying: a new push request can produce another visible notification. Your application-defined notification_id can help your app handle repeated content, but it is not a JPush API idempotency header.

References: JPush REST authentication and Push API.