CodeMash
  • 🚀Backend as a service
  • 🦄Roadmap
  • 🍕Release Notes
  • Installation
    • Managed Service
    • 🏗️AWS-CDK
    • 🏗️Azure
    • 🏗️Docker
    • 🏗️GC
    • 🏗️Terraform
  • dashboard
    • CodeMash Cloud
    • Project
    • Membership
      • Users
      • Roles
      • Policies
      • Triggers
      • Integrations
        • Apple
        • Azure
        • Facebook
        • Google
        • Twitter
      • Settings
    • Database
      • Collections
        • Schema
          • From Template
          • Structure
        • Tabs
        • Triggers
        • Indexes
        • Shared Forms
      • Taxonomies
        • Terms
        • Schema
        • Settings
      • Aggregation
      • Imports
      • Exports
      • Backups
    • Files
      • Integrations
        • CodeMash
        • S3 Bucket
    • Notifications
      • Push
        • Push Templates
        • Push Templates API
        • Push Notifications
        • Push Notifications API
        • Devices
        • Devices API
        • Integrations
          • Firebase
          • One Signal
          • Expo
      • Email
        • Email Templates
        • Emails
        • Integrations
          • AWS SES
          • Twilio Sendgrid
          • Mailgun
      • 🏗️Server events
      • 🏗️Sms
    • Payments
      • Integrations
        • Apple Pay
        • Google Pay
        • Stripe
        • Kevin.
        • Paysera
        • Decta
    • Scheduler
    • Logs & Monitoring
    • Code
      • Functions
        • Function Inputs
        • Function Templates
          • Node.js
          • Python
          • Ruby
          • Java
          • Go
          • .NET Core
      • CodeMash Functions
        • Google Functions
          • Google Calendar
          • Google Gmail
        • Microsoft Functions
          • Microsoft 365 Users
          • Microsoft 365 Calendar
        • Collection Find
        • Collection Update
        • Users Find
        • Image Resize
        • Html To Pdf
        • Word Document
        • Barcode
        • QR Code
        • Send Email
        • Send Notification
        • Email Reminder
        • Notification Reminder
      • Integrations
        • AWS Lambda
        • Google Cloud Functions
        • Azure Functions
  • Other Topics
    • Apple
      • Developer Portal
      • Bundle Identifier
      • Team ID
      • Service ID
      • Key ID
    • Triggers
    • Tokens Binding
      • Project Tokens
      • Initiator Tokens
      • Receiver Tokens
      • Request Tokens
      • Operation based tokens
      • Template Functions
    • Search parameters
      • Paging
      • Filter
      • Sort
      • Projection
    • data-models
    • Errors
  • SDK
    • Node.js
    • TypeScript
    • .NET
    • 🏗️Go Lang
    • 🏗️Flutter
    • 🏗️Swift
    • 🏗️Kotlin
  • CLI
    • 🏗️CodeMash CLI
  • API
    • Get Started
    • Prerequisites
    • How to test?
    • Cors
    • Project
    • Membership
      • Authentication
      • Users
    • Database
      • Collections
        • Aggregate
        • Change Responsibility
        • Count
        • Delete
        • Delete Many
        • Distinct
        • Find
        • Find One
        • Insert
        • Insert Many
        • References
        • Replace
        • Update
        • Update Many
      • Taxonomies
        • Find
    • Files
    • Code
    • Notifications
      • Push
      • Emails
      • Server Events
      • 🏗️Sms
    • Payments
    • Scheduler
    • Logs & Monitoring
Powered by GitBook
On this page
  • Send Push Notification
  • Get Notification
  • Get Notifications
  • Get Notifications Count
  • Read Notification
  • Delete Notification

Was this helpful?

Edit on GitHub
  1. dashboard
  2. Notifications
  3. Push

Push Notifications API

Overview of push notifications API methods

Send Push Notification

POST https://api.codemash.io/:version/notifications/push

Send a mobile notification message.

Path Parameters

Name
Type
Description

version

string

The version of the API endpoint. Current latest v1.

Headers

Name
Type
Description

Authorization

string

Your project's secret key.

x-cm-projectid

string

Your project's ID. Can be passed as a query parameter.

Request Body

Name
Type
Description

templateId

string

The ID of push notification template to use.

roles

array

Roles of users to set as recipients.

users

array

An array of user IDs to be set as recipients.

devices

array

An array of device IDs to be set as recipients.

isNonPushable

boolean

If set as true, creates a silent notification without popping up at the recipient's device.

tokens

object

Key-value pair (string: string) object of custom tokens.

postpone

integer

Amount of milliseconds to postpone sending the notification.

respectTimeZone

boolean

If creating a postponed notification and the recipient's devices have timezone set, then postpones according to the device's timezone.

{
    Result: ""
}
var client = new CodeMashClient(apiKey, projectId);
var pushService = new CodeMashPushService(client);

var response = await pushService.SendPushNotificationAsync(
    new SendPushNotificationRequest
    {
        TemplateId = Guid.Parse("{TEMPLATE_ID}"),
        Users = new List<string> { "{USER_ID}" }
    }
);
use Codemash\CodemashClient;
use Codemash\CodemashPushNotification;

class CodemashService
{
    protected CodemashPushNotification $codemashPushNotification;

    public function __construct()
    {
        $secretKey = '{YOUR_SECRET_KEY}';
        $projectId = '{YOUR_PROJECT_ID}';

        $client = new CodemashClient($secretKey, $projectId);
        $codemashPushNotification = new CodemashPushNotification($client);
    }
    
    public function sendPushNotification()
    {
        $responseData = $this->codemashPushNotification->sendNotification([
            'templateId' => '{TEMPLATE_ID}',
            'users' => [
                '{USER_ID}',
                '{USER_ID}',
                '{USER_ID}',
            ],
        ]);
    }
    
}

Get Notification

GET https://api.codemash.io/:version/notifications/push/:id

Gets a push notification.

Path Parameters

Name
Type
Description

version

string

The version of the API endpoint. Current latest v1.

id

string

The ID of a notification to get.

Headers

Name
Type
Description

Authorization

string

Your project's secret key.

x-cm-projectid

string

Your project's ID. Can be passed as a query parameter.

{
    Result: ""
}
var client = new CodeMashClient(apiKey, projectId);
var pushService = new CodeMashPushService(client);

var response = await pushService.GetNotificationAsync(
    new GetNotificationRequest
    {
        Id = "{NOTIFICATION_ID}"
    }
);
use Codemash\CodemashClient;
use Codemash\CodemashPushNotification;

class CodemashService
{
    protected CodemashPushNotification $codemashPushNotification;

    public function __construct()
    {
        $secretKey = '{YOUR_SECRET_KEY}';
        $projectId = '{YOUR_PROJECT_ID}';

        $client = new CodemashClient($secretKey, $projectId);
        $codemashPushNotification = new CodemashPushNotification($client);
    }
    
    public function getNotification()
    {
        $responseData = $this->codemashPushNotification->getNotification([
            'id' => '{NOTIFICATION_ID}',
        ]);
    }
    
}

Get Notifications

GET https://api.codemash.io/:version/notifications/push

Gets many push notifications.

Path Parameters

Name
Type
Description

version

string

The version of the API endpoint. Current latest v1.

Query Parameters

Name
Type
Description

userId

string

The ID of a user whose notifications to get.

deviceId

string

The ID of a device whose notifications to get.

Headers

Name
Type
Description

Authorization

string

Your project's secret key.

x-cm-projectid

string

Your project's ID. Can be passed as a query parameter.

{
    Result: ""
}
var client = new CodeMashClient(apiKey, projectId);
var pushService = new CodeMashPushService(client);

var response = await pushService.GetNotificationsAsync(
    new GetNotificationsRequest
    {
        UserId = "{USER_ID}"
    }
);
use Codemash\CodemashClient;
use Codemash\CodemashPushNotification;

class CodemashService
{
    protected CodemashPushNotification $codemashPushNotification;

    public function __construct()
    {
        $secretKey = '{YOUR_SECRET_KEY}';
        $projectId = '{YOUR_PROJECT_ID}';

        $client = new CodemashClient($secretKey, $projectId);
        $codemashPushNotification = new CodemashPushNotification($client);
    }
    
    public function getNotifications()
    {
        $responseData = $this->codemashPushNotification->getNotifications([
            'userId' => '{USER_ID}',
        ]);
    }
    
}

If you do not specify user ID or device ID, the method will return notifications directed to the calling user. To get any user's or device's notifications, the calling user need's to have the appropriate permission for that.

Get Notifications Count

GET https://api.codemash.io/:version/notifications/push/count

Gets total and total unread notifications.

Path Parameters

Name
Type
Description

version

string

The version of the API endpoint. Current latest v1.

Query Parameters

Name
Type
Description

userId

string

The ID of a user whose notifications to get.

deviceId

string

The ID of a device whose notifications to get.

Headers

Name
Type
Description

Authorization

string

Your project's secret key.

x-cm-projectid

string

Your project's ID. Can be passed as a query parameter.

{
    "result": {
        "totalCount": 20,
        "totalUnread": 2
    }
}
var client = new CodeMashClient(apiKey, projectId);
var pushService = new CodeMashPushService(client);

var response = await pushService.GetNotificationsCountAsync(
    new GetNotificationsCountRequest
    {
        UserId = "{USER_ID}"
    }
);
use Codemash\CodemashClient;
use Codemash\CodemashPushNotification;

class CodemashService
{
    protected CodemashPushNotification $codemashPushNotification;

    public function __construct()
    {
        $secretKey = '{YOUR_SECRET_KEY}';
        $projectId = '{YOUR_PROJECT_ID}';

        $client = new CodemashClient($secretKey, $projectId);
        $codemashPushNotification = new CodemashPushNotification($client);
    }
    
    public function getNotificationsCount()
    {
        $responseData = $this->codemashPushNotification->getNotificationCount([
            'userId' => '{USER_ID}',
        ]);
    }
    
}

If you do not specify user ID or device ID, the method will return notifications directed to the calling user. To get any user's or device's notifications, the calling user need's to have the appropriate permission for that.

Read Notification

PATCH https://api.codemash.io/:version/notifications/push/:notificationId/read

Marks a particular push notification as read.

Path Parameters

Name
Type
Description

version

string

The version of the API endpoint. Current latest v1.

id

string

The ID of a notification to delete.

Headers

Name
Type
Description

Authorization

string

Your project's secret key.

x-cm-projectid

string

Your project's ID. Can be passed as a query parameter.

Request Body

Name
Type
Description

notificationId

string

The ID of notification to mark as read.

userId

string

The ID of the user at which this notification was directed.

deviceId

string

The ID of device at which this notification was directed.

{
    Result: ""
}
var client = new CodeMashClient(apiKey, projectId);
var pushService = new CodeMashPushService(client);

var response = await pushService.ReadNotificationAsync(
    new MarkNotificationAsReadRequest
    {
        NotificationId = "{NOTIFICATION_ID}"
    }
);
use Codemash\CodemashClient;
use Codemash\CodemashPushNotification;

class CodemashService
{
    protected CodemashPushNotification $codemashPushNotification;

    public function __construct()
    {
        $secretKey = '{YOUR_SECRET_KEY}';
        $projectId = '{YOUR_PROJECT_ID}';

        $client = new CodemashClient($secretKey, $projectId);
        $codemashPushNotification = new CodemashPushNotification($client);
    }
    
    public function readNotification()
    {
        $responseData = $codemashPushNotification->readNotification([
            'id' => '{NOTIFICATION_ID}',
        ]);
    }
    
}

If you do not specify user ID or device ID, the method will assume that notification was directed to a calling user. If you want to set other user's notification as read, you need to have the appropriate permission for that.

Delete Notification

DELETE https://api.codemash.io/:version/notifications/push/:id

Deletes a particular push notification.

Path Parameters

Name
Type
Description

version

string

The version of the API endpoint. Current latest v1.

id

string

The ID of a notification to delete.

Headers

Name
Type
Description

Authorization

string

Your project's secret key.

x-cm-projectid

string

Your project's ID. Can be passed as a query parameter.

{
    Result: ""
}
var client = new CodeMashClient(apiKey, projectId);
var pushService = new CodeMashPushService(client);

var response = await pushService.DeleteNotificationAsync(
    new DeleteNotificationRequest
    {
        Id = "{NOTIFICATION_ID}"
    }
);
use Codemash\CodemashClient;
use Codemash\CodemashPushNotification;

class CodemashService
{
    protected CodemashPushNotification $codemashPushNotification;

    public function __construct()
    {
        $secretKey = '{YOUR_SECRET_KEY}';
        $projectId = '{YOUR_PROJECT_ID}';

        $client = new CodemashClient($secretKey, $projectId);
        $codemashPushNotification = new CodemashPushNotification($client);
    }
    
    public function deleteNotification()
    {
        $responseData = $codemashPushNotification->deleteNotification([
            'id' => '{NOTIFICATION_ID}',
        ]);
    }
    
}
PreviousPush NotificationsNextDevices

Last updated 4 years ago

Was this helpful?