메인 콘텐츠로 건너뛰기
모든 OneSignal 서버 SDK는 동일한 OpenAPI 사양에서 생성되므로 언어에 관계없이 일관된 인터페이스를 공유합니다. 각 SDK는 OneSignal REST API를 래핑하고 요청 및 응답에 대한 타입이 지정된 모델을 제공합니다.

사용 가능한 SDK


설치

npm install @onesignal/node-onesignal

구성

모든 SDK는 API 키를 통한 인증이 필요합니다. 두 가지 키 유형을 사용할 수 있습니다:
  • REST API 키 — 알림 전송, 사용자 관리 등 대부분의 엔드포인트에 필요합니다. 앱의 설정 > 키 및 ID에서 찾을 수 있습니다.
  • Organization API 키 — 앱 생성 또는 목록 조회와 같은 조직 수준 엔드포인트에만 필요합니다. Organization 설정에서 찾을 수 있습니다.
const OneSignal = require('@onesignal/node-onesignal');

const configuration = OneSignal.createConfiguration({
  restApiKey: 'YOUR_REST_API_KEY',
  organizationApiKey: 'YOUR_ORGANIZATION_API_KEY',
});

const client = new OneSignal.DefaultApi(configuration);
API 키를 환경 변수 또는 시크릿 매니저에 저장하세요. 소스 컨트롤에 커밋하지 마세요.

푸시 알림 보내기

세그먼트를 타겟팅하여 웹 및 모바일 구독에 푸시 알림을 보냅니다.
const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.contents = { en: 'Hello from OneSignal!' };
notification.headings = { en: 'Push Notification' };
notification.included_segments = ['Subscribed Users'];

const response = await client.createNotification(notification);
console.log('Notification ID:', response.id);

이메일 보내기

email 채널로 구독에 이메일을 보냅니다.
const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.email_subject = 'Important Update';
notification.email_body = '<h1>Hello!</h1><p>This is an HTML email.</p>';
notification.included_segments = ['Subscribed Users'];
notification.channel_for_external_user_ids = 'email';

const response = await client.createNotification(notification);

SMS 보내기

sms 채널로 구독에 SMS 문자 메시지를 보냅니다.
const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.contents = { en: 'Your SMS message content here' };
notification.included_segments = ['Subscribed Users'];
notification.channel_for_external_user_ids = 'sms';
notification.sms_from = '+15551234567';

const response = await client.createNotification(notification);

전체 API 참조

각 서버 SDK는 동일한 API 엔드포인트 세트를 지원합니다. 사용자, 구독, 세그먼트, 템플릿 등을 포함한 전체 메서드 목록은 SDK의 API 문서를 참조하세요. 기본 REST API에 대해서는 전체 API 참조를 참조하세요.

FAQ

어떤 서버 SDK를 선택해야 하나요?

백엔드 언어에 맞는 SDK를 사용하세요. 모든 서버 SDK는 동일한 OpenAPI 사양에서 생성되고 동일한 엔드포인트를 지원하므로 언어 간 기능이 동일합니다.

REST API 키와 Organization API 키의 차이점은 무엇인가요?

REST API 키는 단일 앱으로 범위가 지정되며 알림 전송 및 사용자 관리와 같은 대부분의 작업에 필요합니다. Organization API 키는 조직으로 범위가 지정되며 앱 생성 또는 목록 조회에만 필요합니다. 대부분의 통합에는 REST API 키만 필요합니다.

SDK 대신 REST API를 직접 사용할 수 있나요?

네. 서버 SDK는 OneSignal REST API를 편리하게 래핑한 것입니다. Bearer 토큰 인증을 지원하는 모든 HTTP 클라이언트를 사용하여 API를 직접 호출할 수 있습니다.

이 SDK들은 자동 생성되나요?

네. 모든 서버 SDK는 OpenAPI Generator를 사용하여 OneSignal OpenAPI 사양에서 생성됩니다. 이를 통해 모든 언어에서 일관된 API 적용 범위가 보장됩니다.