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

# Firebase Cloud Messaging

> Estimated setup time: 1 hour

## Requirements

* Your Firebase project ID
* Service account JSON credentials

Aampe will essentially call the Firebase [Cloud Messaging API](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send) on your behalf.

Setting up Firebase Cloud Messages involves four steps:

1. Enable the Cloud Messaging API
2. Create a custom role for message creation
3. Create a service account
4. Generate a key

<Info>
  All the next steps assume that you start from your Google Cloud Platform console with your Firebase project selected.
</Info>

## Enable the Cloud Messaging API

1. Type "Firebase Cloud Messaging API" in the Search products and resources textbox.
2. Choose **Firebase Cloud Messaging API** from the list.

   <img src="https://mintcdn.com/aameo/E53nzHStcRpXCeaM/images/message-providers/firebase/1-cloud-message-api.png?fit=max&auto=format&n=E53nzHStcRpXCeaM&q=85&s=996d31df8203f6070904dffeee81f8a6" alt="1 Cloud Message Api Pn" width="1345" height="235" data-path="images/message-providers/firebase/1-cloud-message-api.png" />
3. Click on the blue **Enable** button.

   <img src="https://mintcdn.com/aameo/E53nzHStcRpXCeaM/images/message-providers/firebase/2-enable.png?fit=max&auto=format&n=E53nzHStcRpXCeaM&q=85&s=5aa7be78e917762b5e9e71928bf64898" alt="2 Enable Pn" width="1347" height="405" data-path="images/message-providers/firebase/2-enable.png" />

## Create a Custom Role for Message Creation

A custom Role must be created in the system to allow Aampe to trigger notifications using the API because the default roles do not provide granular enough permissions.

1. Type "Roles" in the Search products and resources textbox and select the **Roles (IAM and Admin)** option. This will take you to the Roles page.

   <img src="https://mintcdn.com/aameo/OMv_iADLykfGxp69/images/message-providers/firebase/3-iam.png?fit=max&auto=format&n=OMv_iADLykfGxp69&q=85&s=05d6535d98b8402bcd434a0356e96e0f" alt="3 Iam Pn" width="1450" height="252" data-path="images/message-providers/firebase/3-iam.png" />
2. Click on **+ CREATE ROLE**
3. Fill in the role Title, Description and ID according to your conventions.

   <img src="https://mintcdn.com/aameo/OMv_iADLykfGxp69/images/message-providers/firebase/4-create-role.png?fit=max&auto=format&n=OMv_iADLykfGxp69&q=85&s=bdfdddaa56ffacba73f5ff7edebdfcde" alt="4 Create Role Pn" width="1450" height="597" data-path="images/message-providers/firebase/4-create-role.png" />
4. Click on **+ADD PERMISSIONS**
5. In the window that opens, search for `cloudmessaging.messages.create` using the textbox to the right of the Filter and select the cloudmessaging.messages.create entry that appears.

   <img src="https://mintcdn.com/aameo/OMv_iADLykfGxp69/images/message-providers/firebase/5-add-permissions.png?fit=max&auto=format&n=OMv_iADLykfGxp69&q=85&s=11c2b6192686058206021eda964f5ca8" alt="5 Add Permissions Pn" width="1452" height="420" data-path="images/message-providers/firebase/5-add-permissions.png" />
6. Tick the `cloudmessaging.messages.create` permission and click on **ADD**

   <img src="https://mintcdn.com/aameo/OMv_iADLykfGxp69/images/message-providers/firebase/6-add-permissions-create.png?fit=max&auto=format&n=OMv_iADLykfGxp69&q=85&s=14f84db5a715dca583806aeb73d7a49d" alt="6 Add Permissions Create Pn" width="845" height="530" data-path="images/message-providers/firebase/6-add-permissions-create.png" />
7. Once added, click on **CREATE** to complete the role creation.

   <img src="https://mintcdn.com/aameo/OMv_iADLykfGxp69/images/message-providers/firebase/7-save-permissions.png?fit=max&auto=format&n=OMv_iADLykfGxp69&q=85&s=d032fdc7763cccc288ecb7d2b98bb280" alt="7 Save Permissions Pn" width="1452" height="605" data-path="images/message-providers/firebase/7-save-permissions.png" />

## Create a Service Account

1. Type "Service accounts" in the Search products and resources textbox.
2. Choose **Service accounts (IAM and admin)** from the list. This will take you to the service account page.

   <img src="https://mintcdn.com/aameo/aeDu2ixkITpT7_dh/images/message-providers/firebase/8-service-account.png?fit=max&auto=format&n=aeDu2ixkITpT7_dh&q=85&s=61ee7886210b064482c6c70780a82d8b" alt="8 Service Account Pn" width="1452" height="245" data-path="images/message-providers/firebase/8-service-account.png" />
3. Click on **+ CREATE SERVICE ACCOUNT**

   <img src="https://mintcdn.com/aameo/aeDu2ixkITpT7_dh/images/message-providers/firebase/9-service-account-form.png?fit=max&auto=format&n=aeDu2ixkITpT7_dh&q=85&s=c8beef8fa9df6b197558c1748efd715d" alt="9 Service Account Form Pn" width="1450" height="415" data-path="images/message-providers/firebase/9-service-account-form.png" />
4. Fill in the Service account name, ID and description according to your conventions.

   <img src="https://mintcdn.com/aameo/aeDu2ixkITpT7_dh/images/message-providers/firebase/10-service-account-filled-out.png?fit=max&auto=format&n=aeDu2ixkITpT7_dh&q=85&s=83e5d3b84d2151f48824c8e4b28a4e72" alt="10 Service Account Filled Out Pn" width="1452" height="602" data-path="images/message-providers/firebase/10-service-account-filled-out.png" />
5. Click on **CREATE AND CONTINUE**
6. On the Grant this service account access to the project screen, click on the **Select a role** dropdown.
7. Under **Quick access > Custom**, select the custom role you created in the previous step.

   <img src="https://mintcdn.com/aameo/aeDu2ixkITpT7_dh/images/message-providers/firebase/11-select-custom.png?fit=max&auto=format&n=aeDu2ixkITpT7_dh&q=85&s=f8890537636c2a3f225fa56153a034bc" alt="11 Select Custom Pn" width="1455" height="605" data-path="images/message-providers/firebase/11-select-custom.png" />
8. Click on **+ ADD ANOTHER ROLE** and then on the **Select a role** dropdown.
9. Type "Firebase Cloud Messaging Admin" in the box near the Filter.
10. Select the suggested **Firebase Cloud Messaging Admin** role.

    <img src="https://mintcdn.com/aameo/aeDu2ixkITpT7_dh/images/message-providers/firebase/12-messaging-admin-role.png?fit=max&auto=format&n=aeDu2ixkITpT7_dh&q=85&s=410bbdf25d5516cb3e5925ac5efe0108" alt="12 Messaging Admin Role Pn" width="1452" height="500" data-path="images/message-providers/firebase/12-messaging-admin-role.png" />
11. Click on **DONE** to complete the service account creation.

    <img src="https://mintcdn.com/aameo/aeDu2ixkITpT7_dh/images/message-providers/firebase/13-done.png?fit=max&auto=format&n=aeDu2ixkITpT7_dh&q=85&s=cd9974bed62d557c3f445b0005f5fca0" alt="13 Done Pn" width="1450" height="745" data-path="images/message-providers/firebase/13-done.png" />

## Generate a Key

<Info>
  This step assumes that you created a service account and assigned the "Firebase Cloud Messaging Admin" and custom message creation roles to it.
</Info>

1. In your "Service accounts" page, find the service account you created for Aampe and click on the three dots in the Actions column and select **Manage keys**

   <img src="https://mintcdn.com/aameo/aeDu2ixkITpT7_dh/images/message-providers/firebase/14-generate-key.png?fit=max&auto=format&n=aeDu2ixkITpT7_dh&q=85&s=32ab30aa391eee3723da3cdc5d159861" alt="14 Generate Key Pn" width="1450" height="510" data-path="images/message-providers/firebase/14-generate-key.png" />
2. Click on **ADD KEY** and select **Create new key**

   <img src="https://mintcdn.com/aameo/GkzymqXta-L8Q_YK/images/message-providers/firebase/15-copy-key.png?fit=max&auto=format&n=GkzymqXta-L8Q_YK&q=85&s=dd11dc1244ec31db79e8010c6620e886" alt="15 Copy Key Pn" width="1450" height="560" data-path="images/message-providers/firebase/15-copy-key.png" />
3. Select the **JSON** Key type and click on **CREATE**

   <img src="https://mintcdn.com/aameo/GkzymqXta-L8Q_YK/images/message-providers/firebase/16-json-key.png?fit=max&auto=format&n=GkzymqXta-L8Q_YK&q=85&s=6f94d811e3c48b7d4b379d9d2b2a1f3a" alt="16 Json Key Pn" width="817" height="527" data-path="images/message-providers/firebase/16-json-key.png" />
4. Your browser will download a `.json` file with the key needed by Aampe.

Congrats! Keep your json key secure and let your Aampe technical counterparts know it is ready. They will take it from here.

***
