### Install Dependencies Source: https://github.com/netgsm/netgsm-sms-js/blob/main/examples/README.md Clone the repository and install project dependencies using npm. ```bash git clone https://github.com/netgsm/netgsm-sms-js.git cd netgsm-sms-js npm install ``` -------------------------------- ### Run Basic Usage Example Source: https://github.com/netgsm/netgsm-sms-js/blob/main/examples/README.md Execute the basic usage example to demonstrate core Netgsm SMS API functionalities. ```bash node examples/basic-usage.js ``` -------------------------------- ### ES Modules/TypeScript Quick Start: Check Balance Source: https://github.com/netgsm/netgsm-sms-js/blob/main/README.md Shows how to import and use the Netgsm client with ES Modules or TypeScript to check account balance. This example uses type-safe imports. ```typescript // Option 1: Default import (recommended) import Netgsm from '@netgsm/sms'; // Option 2: Named imports import { Netgsm, SmsStatus, BalanceType } from '@netgsm/sms'; // Configure Netgsm client const netgsm = new Netgsm({ username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD', appname: 'YOUR_APP_NAME' // Optional }); // Type-safe usage async function checkBalance() { try { const balance = await netgsm.checkBalance({ type: BalanceType.CREDIT }); console.log('Balance:', balance); return balance; } catch (error) { console.error('Error:', error); } } ``` -------------------------------- ### ES Modules/TypeScript Quick Start: Check Balance Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Shows how to check account balance using ES Modules or TypeScript. This example utilizes the getBalance method with a specified balance type. ```javascript // Option 1: Default import (recommended) import Netgsm from '@netgsm/sms'; // Option 2: Named imports import { Netgsm, SmsStatus, BalanceType } from '@netgsm/sms'; // Configure Netgsm client const netgsm = new Netgsm({ username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD', appname: 'YOUR_APP_NAME' // Optional }); // Type-safe usage async function checkBalance() { try { const balance = await netgsm.getBalance({ type: BalanceType.CREDIT }); console.log('Balance:', balance); return balance; } catch (error) { console.error('Error:', error); } } ``` -------------------------------- ### Run Scheduled SMS Example Source: https://github.com/netgsm/netgsm-sms-js/blob/main/examples/README.md Execute the scheduled SMS example to demonstrate how to schedule messages for future delivery. ```bash node examples/advanced/scheduled-sms.js ``` -------------------------------- ### Run Bulk SMS Example Source: https://github.com/netgsm/netgsm-sms-js/blob/main/examples/README.md Execute the bulk SMS example to demonstrate sending multiple messages to various recipients in one request. ```bash node examples/advanced/bulk-sms.js ``` -------------------------------- ### Run Error Handling Example Source: https://github.com/netgsm/netgsm-sms-js/blob/main/examples/README.md Execute the error handling example to demonstrate techniques for managing API errors and implementing retries. ```bash node examples/advanced/error-handling.js ``` -------------------------------- ### Set up Development Environment Source: https://github.com/netgsm/netgsm-sms-js/blob/main/CONTRIBUTING.md Instructions for setting up the local development environment, including cloning the repository, installing dependencies, and configuring environment variables. ```bash git clone https://github.com/[KULLANICI_ADINIZ]/netgsm-sms-js.git cd netgsm-sms-js npm install ``` ```dotenv NETGSM_USERCODE=your_usercode NETGSM_PASSWORD=your_password NETGSM_HEADER=your_message_header NETGSM_RECIPIENT=your_test_phone_number ``` -------------------------------- ### Set up Development Environment Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Instructions for setting up the development environment for the netgsm-sms-js project. Includes cloning the repository, installing dependencies, running tests, and building the library. ```bash # Clone the repository git clone https://github.com/netgsm/netgsm-sms-js.git cd netgsm-sms-js # Install dependencies npm install # Run tests npm test # Build the library npm run build ``` -------------------------------- ### Install @netgsm/sms Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Install the @netgsm/sms package using npm or yarn. ```bash npm install @netgsm/sms # or yarn add @netgsm/sms ``` -------------------------------- ### Install @netgsm/sms using Yarn Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Install the Netgsm SMS package using Yarn. This is an alternative to NPM for managing your project dependencies. ```bash yarn add @netgsm/sms ``` -------------------------------- ### Placeholder JavaScript Code Example Source: https://github.com/netgsm/netgsm-sms-js/blob/main/ISSUE_TEMPLATE.md This is a placeholder for a JavaScript code example that demonstrates an issue or a feature request. Users should replace this with their specific code. ```javascript // Add your code example here ``` -------------------------------- ### Test Examples Source: https://github.com/netgsm/netgsm-sms-js/blob/main/CONTRIBUTING.md Example structure for writing unit or integration tests using a describe-it block, demonstrating how to test successful SMS sending and API error handling. ```typescript describe('Netgsm.sendSms', () => { it('should send SMS successfully', async () => { // Test code here }); it('should handle API errors correctly', async () => { // Test code here }); }); ``` -------------------------------- ### CommonJS Quick Start: Send SMS Source: https://github.com/netgsm/netgsm-sms-js/blob/main/README.md Demonstrates how to import and use the Netgsm client in a CommonJS environment to send an SMS. Ensure to replace placeholders with your actual credentials and message details. ```javascript // Option 1: Named imports const { Netgsm, SmsStatus, BalanceType } = require('@netgsm/sms'); // Option 2: Default import const Netgsm = require('@netgsm/sms').default; // or const { default: Netgsm } = require('@netgsm/sms'); // Configure Netgsm client const netgsm = new Netgsm({ username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD', appname: 'YOUR_APP_NAME' // Optional }); // Send SMS async function sendSms() { try { const response = await netgsm.sendRestSms({ msgheader: 'YOUR_HEADER', // SMS header encoding: 'TR', // Turkish character support startdate: '010620241530', // Optional (format: ddMMyyyyHHmm) stopdate: '010620241630', // Optional (format: ddMMyyyyHHmm) messages: [ { msg: 'Message content', no: '5XXXXXXXXX' }, { msg: 'Message content', no: '5YYYYYYYYY' } ] }); console.log('SMS sent:', response); return response.jobid; } catch (error) { console.error('Error:', error); } } // Call the function sendSms(); ``` -------------------------------- ### Install @netgsm/sms using NPM Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Install the Netgsm SMS package using NPM. This is the first step to integrating Netgsm SMS services into your Node.js application. ```bash npm install @netgsm/sms ``` -------------------------------- ### CommonJS Quick Start: Send SMS Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Demonstrates how to send an SMS using CommonJS modules. Configure the Netgsm client with your credentials and call the sendRestSms function. Ensure to replace placeholders with your actual API details. ```javascript // Option 1: Named imports const { Netgsm, SmsStatus, BalanceType } = require('@netgsm/sms');// Option 2: Default import const Netgsm = require('@netgsm/sms').default;// or const { default: Netgsm } = require('@netgsm/sms');// Configure Netgsm client const netgsm = new Netgsm({ username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD', appname: 'YOUR_APP_NAME' // Optional });// Send SMS async function sendSms() { try { const response = await netgsm.sendRestSms({ msgheader: 'YOUR_HEADER', // SMS header encoding: 'TR', // Turkish character support startdate: '010620241530', // Optional (format: ddMMyyyyHHmm) stopdate: '010620241630', // Optional (format: ddMMyyyyHHmm) messages: [ { msg: 'Message content', no: '5XXXXXXXXX' }, { msg: 'Message content', no: '5YYYYYYYYY' } ] }); console.log('SMS sent:', response); return response.jobid; } catch (error) { console.error('Error:', error); } } // Call the functionsendSms(); ``` -------------------------------- ### API: Sending OTP SMS Source: https://github.com/netgsm/netgsm-sms-js/blob/main/README.md Example for sending One-Time Password (OTP) SMS. The message content is limited to 160 characters. ```javascript const response = await netgsm.sendOtpSms({ msgheader: 'YOUR_HEADER', msg: 'OTP Message content', // Max 160 char no: '5XXXXXXXXX' }); ``` -------------------------------- ### Get SMS Report Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Retrieves delivery reports for bulk SMS jobs. ```APIDOC ## `netgsm.getReport(payload)` ### Description Retrieves delivery reports for SMS jobs. ### Method `POST` (Assumed, based on common REST API patterns for reports) ### Endpoint `/sms/report` (Assumed) ### Parameters #### Request Body - **bulkIds** (array) - Required - An array of job IDs for which to retrieve reports. - Each element should be a string representing a job ID. ### Request Example ```json { "bulkIds": ["JOB_ID_1", "JOB_ID_2"] } ``` ### Response #### Success Response (200) - **jobs** (array) - An array of job status objects. - **status** (number) - The delivery status of the job (e.g., 1 for delivered). - Other fields may be present depending on the report details. ``` -------------------------------- ### netgsm.getInbox(payload?) Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Fetches incoming SMS messages received by the account via GET /sms/rest/v2/inbox. Without date filters, each message is listed only once. ```APIDOC ## `netgsm.getInbox(payload?)` — Read Incoming SMS Inbox ### Description Fetches incoming SMS messages received by the account via `GET /sms/rest/v2/inbox`. Without date filters, each message is listed only once — subsequent calls without dates will return no records for already-fetched messages. ### Method `GET` ### Endpoint `/sms/rest/v2/inbox` ### Parameters #### Query Parameters - **startdate** (string) - Optional - Filter by start date in 'ddMMyyyy' format. - **stopdate** (string) - Optional - Filter by end date in 'ddMMyyyy' format. ### Response #### Success Response (200) - **messages** (object[]) - An array of incoming SMS message objects. - **sender** (string) - The sender's phone number or sender ID. - **receiver** (string) - The receiver's phone number or sender ID. - **message** (string) - The content of the SMS message. - **datetime** (string) - The date and time the message was received in 'ddMMyyyyHHmmss' format. ### Response Example ```json { "messages": [ { "sender": "5301234567", "receiver": "MyBrand", "message": "STOP", "datetime": "01062025143022" } ] } ``` ### Error Handling - **'40'**: No messages to display. ``` -------------------------------- ### netgsm.getHeaders(payload?) Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Retrieves all sender headers (alphanumeric sender IDs) registered to the account via GET /sms/rest/v2/msgheader. ```APIDOC ## `netgsm.getHeaders(payload?)` — List Registered Sender IDs ### Description Retrieves all sender headers (alphanumeric sender IDs) registered to the account via `GET /sms/rest/v2/msgheader`. ### Method `GET` ### Endpoint `/sms/rest/v2/msgheader` ### Parameters This endpoint does not require any parameters. ### Response #### Success Response (200) - **msgheaders** (string[]) - An array of registered sender IDs. ### Response Example ```json { "msgheaders": [ "MyBrand", "MyApp", "ALERT" ] } ``` ### Error Handling - **'30'**: Invalid authentication. - **'70'**: Parameter error. ``` -------------------------------- ### Querying SMS Stats Source: https://github.com/netgsm/netgsm-sms-js/blob/main/README.md Get statistics for a specific SMS job using its job ID. ```APIDOC ## Querying SMS Stats ### Description Get statistics for a specific SMS job using its job ID. ### Method `getStats` ### Parameters #### Request Body - **jobid** (string) - Required - The job ID for which to retrieve statistics. ### Request Example ```json { "jobid": "12345678" } ``` ### Response #### Success Response Returns an object containing statistics for the specified job ID. ``` -------------------------------- ### SmsInboxPayload Interface Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/interfaces/SmsInboxPayload.html The SmsInboxPayload interface is used to specify parameters when querying inbox messages. It includes optional fields for application name, start date, and stop date. ```APIDOC ## Interface: SmsInboxPayload ### Description Payload for querying inbox messages. ### Properties * **appname** (string) - Optional - The application name to filter messages. * **startdate** (string) - Optional - The start date for filtering messages (format may vary). * **stopdate** (string) - Optional - The stop date for filtering messages (format may vary). ### Example ```json { "appname": "myApp", "startdate": "2023-01-01", "stopdate": "2023-12-31" } ``` ``` -------------------------------- ### Send SMS with NetGSM Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Use `sendRestSms` to send messages. Specify the header, encoding, and an array of messages with recipient numbers and content. Optional start and end dates can be provided for scheduled sending. ```javascript const response = await netgsm.sendRestSms({ msgheader: 'YOUR_HEADER', encoding: 'TR', // TR, ASCII startdate: '010620241530', // Optional (format: ddMMyyyyHHmm) stopdate: '010620241630', // Optional (format: ddMMyyyyHHmm) messages: [ { msg: 'Message content', no: '5XXXXXXXXX' }, { msg: 'Message content', no: '5YYYYYYYYY' } ] }); ``` -------------------------------- ### Run Tests and Build Library Source: https://github.com/netgsm/netgsm-sms-js/blob/main/README.md Commands to execute the project's test suite and build the library for distribution. ```bash npm test npm run build ``` -------------------------------- ### Client Initialization — new Netgsm(config) Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Constructs and configures the Netgsm API client. Requires username and password; the optional appname is appended as -sdk-js on every request for tracking purposes. ```APIDOC ## Client Initialization — `new Netgsm(config)` Constructs and configures the Netgsm API client. Requires `username` and `password`; the optional `appname` is appended as `-sdk-js` on every request for tracking purposes. ```typescript // ESM / TypeScript import Netgsm from '@netgsm/sms'; import { BalanceType, SmsStatus } from '@netgsm/sms'; const netgsm = new Netgsm({ username: 'YOUR_USERNAME', // required — Netgsm account username password: 'YOUR_PASSWORD', // required — Netgsm account password appname: 'MyApp' // optional — used for per-app analytics }); // CommonJS const { Netgsm, SmsStatus, BalanceType } = require('@netgsm/sms'); const netgsm = new Netgsm({ username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD' }); ``` ``` -------------------------------- ### Netgsm Client Configuration Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Illustrates how to configure the Netgsm client with your username and password. The 'appname' is optional and can be provided for additional identification. ```javascript const netgsm = new Netgsm({ username: 'YOUR_USERNAME', // Required password: 'YOUR_PASSWORD', // Required appname: 'YOUR_APP_NAME' // Optional }); ``` -------------------------------- ### Configuration Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Configure the Netgsm client with your username, password, and optionally an application name. ```APIDOC ## Configuration ```javascript const netgsm = new Netgsm({ username: 'YOUR_USERNAME', // Required password: 'YOUR_PASSWORD', // Required appname: 'YOUR_APP_NAME' // Optional }); ``` ``` -------------------------------- ### Development Commands Source: https://github.com/netgsm/netgsm-sms-js/blob/main/CONTRIBUTING.md Common npm scripts for building, testing, linting, and fixing code quality issues in the project. ```bash npm run build npm test npm run test:unit npm run test:integration npm run lint npm run lint:fix ``` -------------------------------- ### Query Account Balance Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Queries account credit or package/campaign balance via `POST /balance`. You can specify `BalanceType.PACKAGE` for package info, `BalanceType.CREDIT` for credit balance, or `BalanceType.ALLASSETS` for both. ```APIDOC ## `netgsm.checkBalance(payload)` ### Description Queries account credit or package/campaign balance. ### Method `POST` ### Endpoint `/balance` ### Parameters #### Request Body - **stip** (BalanceType) - Required - Type of balance to query. Use `BalanceType.PACKAGE` (1), `BalanceType.CREDIT` (2), or `BalanceType.ALLASSETS` (3). - **appkey** (string) - Optional - Your application key. ### Request Example ```json { "stip": 2, "appkey": "OPTIONAL_APP_KEY" } ``` ### Response #### Success Response (200) - **balance** (string | array) - The requested balance information. This can be a string for credit balance or an array of objects for package balance. ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/netgsm/netgsm-sms-js/blob/main/examples/README.md Set up environment variables in a .env file for API credentials and configuration. ```dotenv NETGSM_USERNAMEyour_username NETGSM_PASSWORD=your_password NETGSM_MESSAGE_HEADER=your_header TEST_PHONE_NUMBER=905xxxxxxxxx ``` -------------------------------- ### Initialize Netgsm Client Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Construct and configure the Netgsm API client with your username and password. An optional appname can be provided for analytics. ```typescript // ESM / TypeScript import Netgsm from '@netgsm/sms'; import { BalanceType, SmsStatus } from '@netgsm/sms'; const netgsm = new Netgsm({ username: 'YOUR_USERNAME', // required — Netgsm account username password: 'YOUR_PASSWORD', // required — Netgsm account password appname: 'MyApp' // optional — used for per-app analytics }); ``` ```javascript // CommonJS const { Netgsm, SmsStatus, BalanceType } = require('@netgsm/sms'); const netgsm = new Netgsm({ username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD' }); ``` -------------------------------- ### Query Account Balance with NetGSM SDK Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Use the `checkBalance` method to query credit, package, or all assets. Ensure the `BalanceType` enum is imported. ```typescript import { BalanceType } from '@netgsm/sms'; async function checkBalance() { try { // Query credit balance const creditBalance = await netgsm.checkBalance({ stip: BalanceType.CREDIT // appkey: 'OPTIONAL_APP_KEY' }); console.log('Credit balance:', creditBalance.balance); // Credit balance: "1500.00" // Query package/campaign info const packageBalance = await netgsm.checkBalance({ stip: BalanceType.PACKAGE }); console.log('Packages:', packageBalance.balance); // Packages: [{ amount: 5000, balance_name: 'Monthly SMS Package' }] // Query all assets const allAssets = await netgsm.checkBalance({ stip: BalanceType.ALLASSETS }); console.log('All assets:', allAssets.balance); } catch (err) { console.error(`Balance Error ${err.code}: ${err.description}`); } } ``` -------------------------------- ### NetgsmConfig Interface Properties Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/interfaces/NetgsmConfig.html This interface outlines the configuration options required to initialize the Netgsm client. It includes mandatory username and password, along with an optional application name. ```APIDOC ## Interface: NetgsmConfig Configuration interface for Netgsm client. ### Properties * **username** (string) - Required - Netgsm API username. * **password** (string) - Required - Netgsm API password. * **appname** (string) - Optional - Optional application name for tracking. ``` -------------------------------- ### Check NetGSM Balance Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Use `getBalance` to check your account balance. Specify the `type` parameter to differentiate between package/campaign info (1) and credit info (2). ```javascript const balance = await netgsm.getBalance({ type: BalanceType.CREDIT // 1: Package/campaign info, 2: Credit info }); ``` -------------------------------- ### List NetGSM Headers Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Fetch a list of available SMS headers using the `getHeaders` method. ```javascript const headers = await netgsm.getHeaders(); ``` -------------------------------- ### getBalance Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Query the account balance. ```APIDOC ## getBalance ### Description Query the account balance. ### Method `getBalance(options)` ### Parameters #### Request Body - **type** (BalanceType) - Required - The type of balance to query (e.g., `BalanceType.CREDIT`). ### Request Example ```json { "type": "CREDIT" } ``` ### Response #### Success Response (200) - **balance** (string) - The account balance. #### Response Example ```json { "balance": "100.50" } ``` ``` -------------------------------- ### Create Git Branch Source: https://github.com/netgsm/netgsm-sms-js/blob/main/CONTRIBUTING.md Commands for creating new Git branches based on the type of contribution (feature, bug fix, documentation). ```bash git checkout -b feature/new-feature git checkout -b fix/bug-fix git checkout -b docs/documentation-update ``` -------------------------------- ### Listing Headers Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Retrieve a list of available SMS headers associated with your account. ```APIDOC ## Listing Headers ### Description Retrieve a list of available SMS headers associated with your account. ### Method `getHeaders` ### Parameters (No parameters required) ### Request Example ```javascript const headers = await netgsm.getHeaders(); ``` ### Response (Response details not provided in source) ``` -------------------------------- ### Checking Balance Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Check the current balance or package information for your NetGSM account. ```APIDOC ## Checking Balance ### Description Check the current balance or package information for your NetGSM account. ### Method `getBalance` ### Parameters #### Request Body - **type** (BalanceType) - Required - Specifies the type of balance information to retrieve. - **CREDIT**: Retrieves credit information. - **PACKAGE**: Retrieves package/campaign info. ### Request Example ```javascript const balance = await netgsm.getBalance({ type: BalanceType.CREDIT }); ``` ### Response (Response details not provided in source) ``` -------------------------------- ### BalancePayload Interface Definition Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/interfaces/BalancePayload.html This interface is used to specify the parameters for balance-related operations. It includes an optional 'appkey' for authentication and a required 'stip' field to indicate the balance type. ```APIDOC ## Interface: BalancePayload ### Description Represents the payload structure for balance-related operations. ### Properties * **appkey** (string) - Optional - An optional application key for authentication. * **stip** (BalanceType) - Required - The type of balance to query. This should be one of the values defined in the `BalanceType` enum. ``` -------------------------------- ### Conventional Commits Format Source: https://github.com/netgsm/netgsm-sms-js/blob/main/CONTRIBUTING.md The standard format for commit messages, including type, scope, description, body, and footers. ```markdown [optional scope]: [optional body] [optional footer(s)] ``` -------------------------------- ### Query SMS Statistics with netgsm.getStats Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Returns aggregate delivery statistics for a job ID. Includes total SMS count, message length, charge summary, and domestic/international breakdown. An optional send date can be provided for filtering. ```typescript async function getStats(jobId: string) { try { const stats = await netgsm.getStats({ jobid: jobId, // senddate: '01062025' // optional }); for (const s of stats.stats ?? []) { console.log(`Status: ${s.status}`); console.log(`Total SMS: ${s.totalSms}`); console.log(`Total message length: ${s.totalMessageLength}`); console.log(`Charge statement: ${s.chargeStatement}`); console.log(`Domestic: ${s.domestic}`); } // Status: DELIVERED // Total SMS: 2 // Total message length: 320 // Charge statement: 2 credits // Domestic: true } catch (err) { console.error(`Stats Error ${err.code}: ${err.description}`); } } ``` -------------------------------- ### List Inbox Messages with NetGSM Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Retrieve messages from the inbox using `getInbox`. You can filter messages by specifying `startdate` and `stopdate` in `ddMMyyyy` format. ```javascript const inbox = await netgsm.getInbox({ startdate: '01012024', // Start date (format: ddMMyyyy) stopdate: '31012024' // End date (format: ddMMyyyy) }); ``` -------------------------------- ### Query SMS Report with NetGSM Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/index.html Retrieve the status report for sent SMS jobs using `getReport`. Provide the `bulkIds` array containing the job ID(s) obtained after sending. ```javascript const report = await netgsm.getReport({ bulkIds: ['12345678'] // Job ID received after sending }); ``` -------------------------------- ### BasePayload Interface Definition Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/interfaces/BasePayload.html This interface serves as a base for API request payloads, providing optional fields for application name and date ranges. ```APIDOC ## Interface: BasePayload ### Description Base payload interface for API requests. ### Properties * **appname** (string) - Optional - The name of the application. * **startdate** (string) - Optional - The start date for filtering. * **stopdate** (string) - Optional - The end date for filtering. ### Hierarchy * BasePayload * [ReportPayload](ReportPayload.html) ### Example Usage (Conceptual) ```json { "appname": "MySmsApp", "startdate": "2023-01-01", "stopdate": "2023-12-31" } ``` ``` -------------------------------- ### Send SMS Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Sends SMS messages. Supports scheduling with `startdate` and IYS (İleti Yönetim Sistemi) filtering for commercial messages. ```APIDOC ## `netgsm.sendRestSms(payload)` ### Description Sends SMS messages, with options for scheduling and IYS filtering. ### Method `POST` ### Endpoint `/sms/send` (Assumed, based on common REST API patterns for SMS) ### Parameters #### Request Body - **msgheader** (string) - Required - Sender ID or message header. - **encoding** (string) - Required - Message encoding (e.g., 'TR' for Turkish). - **startdate** (string) - Optional - For scheduled SMS, in `ddMMyyyyHHmm` format. - **iysfilter** (string) - Optional - IYS filter type ('0', '11', or '12'). - **messages** (array) - Required - An array of message objects. - **msg** (string) - Required - The message content. - **no** (string) - Required - Recipient's phone number. ### Request Example (Scheduled SMS) ```json { "msgheader": "MyBrand", "encoding": "TR", "startdate": "251220231430", "messages": [ { "msg": "Reminder: your appointment is in 1 hour.", "no": "5301234567" } ] } ``` ### Request Example (Bulk SMS with IYS Filter) ```json { "msgheader": "MyBrand", "encoding": "TR", "iysfilter": "11", "messages": [ { "msg": "Hi Alice! 20% off on your next order. Code: SAVE20", "no": "5301234567" }, { "msg": "Hi Bob! Your exclusive offer awaits. Code: BOB10", "no": "5307654321" }, { "msg": "Hi Carol! Flash sale ends tonight!", "no": "5309876543" } ] } ``` ### Response #### Success Response (200) - **jobid** (string) - The ID of the sent job. ``` -------------------------------- ### BalanceType Enumeration Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/enums/BalanceType.html The BalanceType enumeration provides codes to specify the type of balance information requested. It includes CREDIT for credit information and PACKAGE for package or campaign information. ```APIDOC ## Enumeration: BalanceType ### Description Balance query type codes. ### Enumeration Members * **CREDIT** * Value: `2` * Description: Credit information. * Defined in: [enums.ts:70](https://github.com/netgsm/netgsm-sms-js/blob/47a95a6cdb6d031e21588189aae296c4522fc77e/src/enums.ts#L70) * **PACKAGE** * Value: `1` * Description: Package/campaign information. * Defined in: [enums.ts:68](https://github.com/netgsm/netgsm-sms-js/blob/47a95a6cdb6d031e21588189aae296c4522fc77e/src/enums.ts#L68) ``` -------------------------------- ### Schedule and Cancel SMS with NetGSM SDK Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Send an SMS at a future date/time using `sendRestSms` with a formatted `startdate`. The `formatDateForNetgsm` helper ensures the correct `ddMMyyyyHHmm` format. Use `cancelSms` with the returned `jobid` to cancel. ```javascript const { Netgsm } = require('@netgsm/sms'); const netgsm = new Netgsm({ username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD' }); function formatDateForNetgsm(date) { const dd = date.getDate().toString().padStart(2, '0'); const MM = (date.getMonth() + 1).toString().padStart(2, '0'); const yyyy = date.getFullYear(); const HH = date.getHours().toString().padStart(2, '0'); const mm = date.getMinutes().toString().padStart(2, '0'); return `${dd}${MM}${yyyy}${HH}${mm}`; } async function scheduleAndCancel() { // Schedule for 1 hour from now const sendAt = new Date(); sendAt.setHours(sendAt.getHours() + 1); const { jobid } = await netgsm.sendRestSms({ msgheader: 'MyBrand', encoding: 'TR', startdate: formatDateForNetgsm(sendAt), messages: [{ msg: 'Reminder: your appointment is in 1 hour.', no: '5301234567' }] }); console.log('Scheduled, job ID:', jobid); // Immediately cancel it const cancel = await netgsm.cancelSms({ jobid }); console.log('Cancelled:', cancel.jobid); } scheduleAndCancel().catch(console.error); ``` -------------------------------- ### List Registered Sender IDs with netgsm.getHeaders Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Retrieves all sender headers (alphanumeric sender IDs) registered to the account. Handles potential errors like invalid authentication or parameter issues. ```typescript async function listHeaders() { try { const result = await netgsm.getHeaders(); console.log('Registered headers:', result.msgheaders); // Registered headers: ['MyBrand', 'MyApp', 'ALERT'] } catch (err) { // MsgHeaderErrorCode: '30' = invalid auth, '70' = parameter error console.error(`Headers Error ${err.code}: ${err.description}`); } } ``` -------------------------------- ### Read Incoming SMS Inbox with netgsm.getInbox Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Fetches incoming SMS messages received by the account. Supports date range filtering. Without date filters, each message is listed only once. ```typescript async function readInbox() { try { const inbox = await netgsm.getInbox({ startdate: '01062025', // ddMMyyyy stopdate: '30062025' // ddMMyyyy }); for (const msg of inbox.messages ?? []) { console.log(`From: ${msg.sender} → To: ${msg.receiver}`); console.log(`Message: ${msg.message}`); console.log(`Received: ${msg.datetime}`); } // From: 5301234567 → To: MyBrand // Message: STOP // Received: 01062025143022 } catch (err) { // InboxErrorCode: '40' = no messages to display console.error(`Inbox Error ${err.code}: ${err.description}`); } } ``` -------------------------------- ### Query SMS Delivery Report with netgsm.getReport Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Retrieves per-recipient delivery statuses for one or more job IDs. Supports pagination and date-range filtering. Each job entry contains the recipient number, delivery status, operator code, and delivery timestamp. ```typescript import { SmsStatus, OperatorCode } from '@netgsm/sms'; async function checkReport(jobId: string) { try { const report = await netgsm.getReport({ bulkIds: [jobId], // array of job IDs returned by sendRestSms pageNumber: 1, pageSize: 100 // startdate / stopdate: 'ddMMyyyyHHmmss' — optional date filter }); for (const job of report.jobs ?? []) { const delivered = job.status === SmsStatus.SENT; console.log( `Recipient: ${job.number} | ` + `Status: ${delivered ? 'DELIVERED' : 'NOT DELIVERED'} (${job.status}) | ` + `Operator: ${OperatorCode[job.operator] ?? job.operator} | ` + `Delivered at: ${job.deliveredDate ?? 'N/A'}` ); } // Recipient: 5301234567 | Status: DELIVERED (1) | Operator: TURKCELL | Delivered at: 01062025153200 } catch (err) { // ReportErrorCode: '60' = no records, '80' = rate limit (10 req/min) console.error(`Report Error ${err.code}: ${err.description}`); } } ``` -------------------------------- ### Send Bulk SMS with IYS Filter using NetGSM SDK Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Send personalized bulk SMS messages using `sendRestSms` with the `iysfilter` option for commercial message consent. The `getReport` method can be used to poll delivery status. ```javascript const { Netgsm } = require('@netgsm/sms'); const netgsm = new Netgsm({ username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD', appname: 'MyApp' }); async function sendBulkWithIys() { // iysfilter values: // '0' — informational (no IYS check) // '11' — commercial to individual (IYS checked) // '12' — commercial to merchant (IYS checked) const response = await netgsm.sendRestSms({ msgheader: 'MyBrand', encoding: 'TR', iysfilter: '11', // commercial message to individuals messages: [ { msg: 'Hi Alice! 20% off on your next order. Code: SAVE20', no: '5301234567' }, { msg: 'Hi Bob! Your exclusive offer awaits. Code: BOB10', no: '5307654321' }, { msg: 'Hi Carol! Flash sale ends tonight!', no: '5309876543' }, ] }); console.log('Bulk job ID:', response.jobid); // Poll report after delivery window await new Promise(r => setTimeout(r, 5000)); const report = await netgsm.getReport({ bulkIds: [response.jobid] }); const delivered = report.jobs?.filter(j => j.status === 1).length ?? 0; console.log(`Delivered: ${delivered} / ${report.jobs?.length ?? 0}`); // Delivered: 3 / 3 } sendBulkWithIys().catch(console.error); ``` -------------------------------- ### netgsm.getStats(payload) Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Returns aggregate delivery statistics for a job ID via POST /sms/rest/v2/stats, including total SMS count, message length, charge summary, and domestic/international breakdown. ```APIDOC ## `netgsm.getStats(payload)` — Query SMS Statistics ### Description Returns aggregate delivery statistics for a job ID via `POST /sms/rest/v2/stats`, including total SMS count, message length, charge summary, and domestic/international breakdown. ### Method `POST` ### Endpoint `/sms/rest/v2/stats` ### Parameters #### Request Body - **jobid** (string) - Required - The ID of the job to retrieve statistics for. - **senddate** (string) - Optional - Filter statistics by send date in 'ddMMyyyy' format. ### Response #### Success Response (200) - **stats** (object[]) - An array of statistics objects. - **status** (string) - The delivery status. - **totalSms** (number) - The total number of SMS messages. - **totalMessageLength** (number) - The total message length. - **chargeStatement** (string) - The charge summary. - **domestic** (boolean) - Indicates if the messages were domestic. ### Response Example ```json { "stats": [ { "status": "DELIVERED", "totalSms": 2, "totalMessageLength": 320, "chargeStatement": "2 credits", "domestic": true } ] } ``` ### Error Handling - **'60'**: Job ID not found. - **'30'**: Invalid authentication. ``` -------------------------------- ### API: Querying SMS Report Source: https://github.com/netgsm/netgsm-sms-js/blob/main/README.md How to retrieve the delivery report for sent SMS messages using their job IDs. ```javascript const report = await netgsm.getReport({ bulkIds: ['12345678'] // Job ID received after sending }); ``` -------------------------------- ### API: Sending SMS Source: https://github.com/netgsm/netgsm-sms-js/blob/main/README.md Demonstrates the parameters for sending an SMS using the sendRestSms method. Supports Turkish characters and optional scheduling. ```javascript const response = await netgsm.sendRestSms({ msgheader: 'YOUR_HEADER', encoding: 'TR', startdate: '010620241530', // Optional (format: ddMMyyyyHHmm) stopdate: '010620241630', // Optional (format: ddMMyyyyHHmm) messages: [ { msg: 'Message content', no: '5XXXXXXXXX' }, { msg: 'Message content', no: '5YYYYYYYYY' } ] }); ``` -------------------------------- ### ReportResponse Interface Source: https://github.com/netgsm/netgsm-sms-js/blob/main/docs/interfaces/ReportResponse.html This interface defines the structure of the API response when fetching SMS reports. It includes optional code and description fields, and an array of job details. ```APIDOC ## Interface: ReportResponse ### Description API response structure for fetching SMS reports. ### Properties * **code** (string) - Optional - The status code of the report. * **description** (string) - Optional - A description of the report status. * **jobs** (Array) - Optional - An array of job details. #### Type declaration for jobs: * **deliveredDate** (string) - Optional - The date the SMS was delivered. * **errorCode** (number) - Optional - The error code associated with the job. * **jobid** (string) - Required - The unique identifier for the job. * **msglen** (number) - Required - The length of the message. * **number** (string) - Required - The recipient's phone number. * **operator** (number) - Required - The operator code. * **referansID** (string) - Optional - The reference ID for the job. * **status** (number) - Required - The status of the job. ``` -------------------------------- ### netgsm.getReport(payload) Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Retrieves per-recipient delivery statuses for one or more job IDs via POST /sms/rest/v2/report. Supports pagination and date-range filtering. ```APIDOC ## `netgsm.getReport(payload)` — Query SMS Delivery Report ### Description Retrieves per-recipient delivery statuses for one or more job IDs via `POST /sms/rest/v2/report`. Supports pagination and date-range filtering. Each job entry contains the recipient number, delivery status, operator code, and delivery timestamp. ### Method `POST` ### Endpoint `/sms/rest/v2/report` ### Parameters #### Request Body - **bulkIds** (string[]) - Required - array of job IDs returned by sendRestSms - **pageNumber** (number) - Optional - The page number for pagination. - **pageSize** (number) - Optional - The number of records per page. - **startdate** (string) - Optional - Filter by start date in 'ddMMyyyyHHmmss' format. - **stopdate** (string) - Optional - Filter by end date in 'ddMMyyyyHHmmss' format. ### Response #### Success Response (200) - **jobs** (object[]) - An array of job status objects. - **number** (string) - The recipient's phone number. - **status** (SmsStatus) - The delivery status of the SMS. - **operator** (OperatorCode) - The operator code of the recipient. - **deliveredDate** (string) - The date and time the SMS was delivered in 'ddMMyyyyHHmmss' format. ### Response Example ```json { "jobs": [ { "number": "5301234567", "status": 1, "operator": "TURKCELL", "deliveredDate": "01062025153200" } ] } ``` ### Error Handling - **'60'**: No records found. - **'80'**: Rate limit exceeded (10 requests per minute). ``` -------------------------------- ### Querying SMS Report Source: https://github.com/netgsm/netgsm-sms-js/blob/main/README.md Retrieve the delivery report for sent SMS messages using their job IDs. ```APIDOC ## Querying SMS Report ### Description Retrieve the delivery report for sent SMS messages using their job IDs. ### Method `getReport` ### Parameters #### Request Body - **bulkIds** (array) - Required - An array of job IDs for which to retrieve reports. ### Request Example ```json { "bulkIds": ["12345678"] } ``` ### Response #### Success Response Returns an object containing the delivery status for the specified job IDs. ``` -------------------------------- ### Sending OTP SMS Source: https://github.com/netgsm/netgsm-sms-js/blob/main/README.md Send One-Time Password (OTP) SMS messages. This method is optimized for sending short, time-sensitive OTP codes. ```APIDOC ## Sending OTP SMS ### Description Send One-Time Password (OTP) SMS messages. This method is optimized for sending short, time-sensitive OTP codes. ### Method `sendOtpSms` ### Parameters #### Request Body - **msgheader** (string) - Required - The header for the SMS message. - **msg** (string) - Required - The OTP message content (Max 160 characters). - **no** (string) - Required - The recipient's phone number. ### Request Example ```json { "msgheader": "YOUR_HEADER", "msg": "OTP Message content", "no": "5XXXXXXXXX" } ``` ### Response #### Success Response Returns an object containing the `jobid` for the sent OTP SMS. ``` -------------------------------- ### Send SMS (REST v2) Source: https://context7.com/netgsm/netgsm-sms-js/llms.txt Send one or more SMS messages using the REST v2 API. Supports instant and scheduled delivery, Turkish character encoding, and custom per-recipient messages. Error handling is provided for API responses. ```typescript import Netgsm from '@netgsm/sms'; const netgsm = new Netgsm({ username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD' }); async function sendSms() { try { // Instant send — different message per recipient const response = await netgsm.sendRestSms({ msgheader: 'MyBrand', // registered sender ID encoding: 'TR', // 'TR' for Turkish chars, 'ASCII' otherwise messages: [ { msg: 'Hello Alice, your order is ready!', no: '5301234567' }, { msg: 'Hello Bob, your order has shipped.', no: '5307654321' }, ] }); console.log('Job ID:', response.jobid); // Job ID: 1234567890 // Scheduled send with expiry window const scheduled = await netgsm.sendRestSms({ msgheader: 'MyBrand', encoding: 'TR', startdate: '010620251530', // ddMMyyyyHHmm — send starting 01 Jun 2025 15:30 stopdate: '010620251630', // ddMMyyyyHHmm — discard if not sent by 16:30 messages: [{ msg: 'Campaign message', no: '5301234567' }] }); console.log('Scheduled Job ID:', scheduled.jobid); } catch (err) { // err.status — HTTP status code // err.code — SendSmsErrorCode ('30' = invalid auth, '40' = bad header, …) // err.description — human-readable explanation console.error(`Error ${err.code}: ${err.description}`); } } sendSms(); ```