Launching integration on Node.js Express
This guide will help you set up the simplest test integration in JavaScript from scratch to work with notifications. You can check if your server is processing the notification.
You will need a Node.js and Java are at least version 11, as well as Curl for checking the server operation
Download the OpenAPI specification
-
Open the folder where you want to save the specification. In this manual, it will be referred to as
<project_directory>
. -
Run the command prompt in it.
-
Write a command:
git clone https://github.com/yandex-market/yandex-market-notification-api.git
- Download the specification of the Market notification service from GitHub.
- Unzip the archive to the folder where you want to save the specification. In this manual, it will be referred to as
<project_directory>
.
Generate a server
-
Open the folder
yandex-market-notification-api
, which appeared in the previous step. -
Run the command prompt in it.
-
Write a command:
npx @openapitools/openapi-generator-cli generate -i <path_to_openapi.yaml> -g nodejs-express-server -o <output_path>
As a output path specify the folder where your project will be located.
If openapitools until it is installed, agree to the installation. In the folder output path the client's files will appear.
Example
Let's say you downloaded an archive and unpacked it. The specification is in the folder
<project_directory>/yandex-market-notification-api
.Do you want to place the project in a folder
<project_directory>/market-integration
.1. Open the folder
<project_directory>/yandex-market-notification-api
.2. Run the command prompt in it.
3. In the console that opens, write:
``` npx @openapitools/openapi-generator-cli generate -i openapi/openapi.yaml -g javascript -o ../market-integration ```
4. If you are prompted to install the generator, enter Y and click Enter.
Implement notification processing
-
Open the directory with the generated code in the IDE.
-
In
service/NotificationService.js
the notification processing logic is located. Add a simple code to process the notification with the typePING
:const Service = require('./Service'); const logger = require('../logger'); const sendNotification = (sendNotificationRequest) => new Promise( async (resolve, reject) => { try { if (sendNotificationRequest.body.notificationType == 'PING') { logger.info("PING notification processed") } // Возвращаем обязательное тело ответа resolve(Service.successResponse({ name: "shop", time: new Date().toISOString(), version: "1.0.0" })); } catch (e) { reject(Service.rejectResponse( e.message || 'Invalid input', e.status || 405, )); } }, ); module.exports = { sendNotification, };
-
Write to the console
node index.js
. The server will start. -
In a separate terminal window, make a test request to your server:
curl -X POST -L 'http://localhost:8080/notification' -H 'Content-Type: application/json' -d '{"notificationType": "PING", "time": "2025-01-01T00:00:00.000Z"}'
-
In the response you will see
{"name":"shop","time":"2025-02-28T12:32:01.918Z","version":"1.0.0"}
, and in the server logs the messagePING notification processed
.