> ## Documentation Index
> Fetch the complete documentation index at: https://docs.auxia.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Sample Push Notification Script

> Example script for implementing Firebase push notifications

## Pre-requisites

1. FCM token: In the [Sample Flutter Set up](/deploying-auxia/delivery-integrations/firebase-push-notifications-integration-manual/sample-flutter-set-up) section, the implementation logs the FCM token for the developer's device.
2. Access to the API: In the [Service Account](/deploying-auxia/delivery-integrations/firebase-push-notifications-integration-manual/enable-auxia-to-send-notification#service-account) section, we downloaded JSON for a service account with access to the API.

[Complete implementation for reference](#complete-implementation).

<aside>
  💡

  Tip: A [local debugger](https://firebase.google.com/docs/analytics/debugview) can be used to debug the notification reception and events logging.

  <img src="https://mintcdn.com/auxia/XsfpA_ObWj7oESRX/img/firebase-push-notifications/debug-view.png?fit=max&auto=format&n=XsfpA_ObWj7oESRX&q=85&s=5b2b02924d09ce637611ac55e0b54a29" alt="Firebase Analytics Debug View" width="898" height="1072" data-path="img/firebase-push-notifications/debug-view.png" />
</aside>

## \[Sample] Python Push Notification Sender

The following Python script demonstrates how to send push notifications using Firebase Cloud Messaging:

```python theme={null}
# sender.py
# Refer to the Service Account section for the JSON key file creation.
# Refer to the Sample Flutter Setup section for FCM token creation.

import time
import firebase_admin
from firebase_admin import messaging, credentials

# Firebase service account JSON file (Replace with the correct path)
SERVICE_ACCOUNT_PATH = "path/to/file"

# Firebase Cloud Messaging (FCM) token of the target device (Replace with actual token)
FCM_TOKEN = "Get this token from the client device set up."

# Initialize Firebase Admin SDK if not already initialized
if not firebase_admin._apps:
    cred = credentials.Certificate(SERVICE_ACCOUNT_PATH)
    firebase_admin.initialize_app(cred)

# Create a notification message
message = messaging.Message(
    notification=messaging.Notification(
        title="Sample Title",
        body="Sample Body."
    ),
    data={"timestamp": str(time.time())},
    token=FCM_TOKEN,  # Target device token
)

# Send the notification
try:
    response = messaging.send(message)
    print("Successfully sent message:", response)
except Exception as e:
    print("Failed to send message:", str(e))
```

## Complete Implementation

For a complete Flutter implementation, refer to the [Flutter Sample Setup](/deploying-auxia/delivery-integrations/firebase-push-notifications-integration-manual/sample-flutter-set-up) which includes all the necessary code to receive and handle push notifications in your mobile application.

## Debugging

A local debugger can be used to debug the notification reception and events logging. Firebase provides a debug view in the Firebase console that allows you to see events as they occur.
