Generate Permanent Access Token For WhatsApp

AMIT SINGH
7 min readOct 24, 2022

--

It’s time to get back to the part that we left out in the previous blog. In the previous blog, we completed “Basic Setup for Salesforce + WhatsApp Integration”, now it’s time to move on to the next important thing which is “Generating Permanent Access Token for Facebook”.

Setting Up Base For Generating Permanent Access Token (PAT)

If you have already logged in to your Facebook Account, you will be redirected to the below-shown page else do follow the previous blog for checking out signup options. Next click on “My Apps”

Here, you will find the App that you have created by following the previous blog. It will appear as shown below:-

Click on the demo App (“Salesforce+WP” in my case) that you have created. Once done, you will be redirected to the App detail page. From the sidebar, click on the “WhatsApp” Section. Within this “WhatsApp” section, click on the “Getting Started” option. Here, you will be able to find all the details that you have set up from the previous blog. In the “Getting Started” section, you will find the “Temporary Access Token”. The major drawback of this “Temporary Access Token” is that it will get expired within 23 hours. To avoid this tedious task, it’s better to Generate a Permanent Access Token”.

Initializing “Permanent Access Token” Generation

To begin the process of “Permanent Access Token” generation, Click on the “Configuration” option under the WhatsApp section. In the “Configuration” section, you will see an option called Permanent Token. Click on the “Learn how to create permanent token” link which will redirect you to the documentation page of Facebook Developer.

Scroll down to the “Required Assets” section on the documentation page of Facebook Developer.

Please make sure that you have completed the steps mentioned in the “Required Assets” section. If you have followed all the steps of our blogs, you should have completed some of the above-mentioned steps like creating a meta–Developer Account, creating a Business App, and adding it to your Business Manager Account. Now, the next step we need to perform is to generate an access token. For this, click on the first link under the “An access token” section as highlighted in the image below: –

This link will land you on to new page which will show all the points that are needed to “Generate Permanent Access Token”. Scroll down to the “Steps to add new system user” section. Click on the first step i.e “Go to Business Settings”

Creating System User

Clicking on the above link will take you to the setting page of the Business Account that you have already created. From Sidebar, select “System users” under the “Users” section. Click on the “Add” button. A pop-up will appear stating “Non-discrimination policy”. Leave all the options and click on the “I accept” button. After that, another pop-up will appear asking you to “Create System User”.

Here, you need to enter “System Username” and select “Admin” as System User Role. Once this step is completed, again pop-up will appear stating “Non-discrimination policy”. Leave all the options and click on the “I accept” button. Now, you need to add this “Admin” user to the WhatsApp Account.

Adding Newly Created “System User” To The WhatsApp Account

For this, scroll down to the “Accounts” section from the sidebar. Here, you will find an option named “WhatsApp Account”. Click on the “WhatsApp Account” option to add the newly created “System User”.

Click on the “Add People” button. Now, it will show all the users that you have created. From the list, you need to select the recently created “System User”. After that, assign “Partial Access” and “Full Control” to the selected user and click on “Assign”. This marks the completion of adding the “System User” Process.

Adding Newly Created “System User” To The Demo App

Also, we need to add “System User” to the demo app that we have created (Salesforce+WP in my case). To achieve this milestone, scroll down to the “Accounts” section from the sidebar. Here, you will find an option named “Apps”. Click on the “Apps” option to add the newly created “System User”. Click on the “Add People” button. Now, it will show all the users that you have created. From the list, you need to select the recently created “System User”. After that, assign “Partial Access” to develop the app and “Full Control” to the selected user and click on “Assign”. This marks the completion of adding the “System User” Process.

Generating a “Permanent Access Token”

From the Sidebar, scroll up to the “Users” section. Click on the “System Users” option under the “Users” section, select the recently created “System User” and then click on “Generate New Token”.

Once you click “Generate New Token”, a pop-up will appear asking you to select your Demo app. Select your demo app (“Salesforce+WP” in my case) and assign two important permissions for this Demo App.

  1. Whatsapp_business_messaging
  2. Whatsapp_business_management

After this, click on the “Generate Token” button which will appear at the bottom of this popup.

After this, Permanent Access Token will get generated. For the safer side, it will be better to copy and paste the Token on your Notepad as it won’t be stored on Facebook.

Using “Postman” To Send Messages To WhatsApp

First thing first. Now get back to the application that you have created by following the steps from the previous blog. If you are still confused follow these steps quickly.

Go to https://developers.facebook.com/ à Click on “My Appsà Select the demo app that you have created (“Salesforce+WP” in my case).

Now, scroll down to the “WhatsApp” section from the sidebar. Select the “Getting Started” option under the WhatsApp section. In the “Send and Receive Messages” section, select your WhatsApp number in the “To” section. After this, come down to the “Step 2: Send messages with the API” section, copy the newly generated command and paste it on your notepad (for safety & backup purposes).

Since we are going to send messages to WhatsApp through Postman, it’s highly advised to download & install Postman through this link. Once you have installed Postman, go ahead and open the “Postman” App and click on the “Import” button (at the top left). Here you will find multiple tabs under the Import button. Select the “raw text” tab and paste the command URL that you have copied from the previous step. Once done, click on the “Continue” button and then on the “Import” button. So, this will generate a request for you.

I’ll break down this URL, to make understanding clearer.

Now, the basic need of using “Postman” is to send messages. So below this URL, you will find an option named “Body”. Go to that option, then click on “Beautify”. This will show you the message that will be sent. Next, click on the “Headers” option. Under “Headers”, you will find two keys

  1. Authorization: — This contains the Temporary Access Token (which will expire within 23 hours). Here you need to replace it with a Permanent Access Token. For that, remove everything from the “Authorization” and then type “Bearer”, give space, and paste the Permanent Access Token that you have saved in your Notepad.
  2. Content-Type

Now, go ahead and click on the “Send” Button next to the URL. This will send a message to the mentioned WhatsApp number, and you can also see the confirmation message in the body section of the Postman as shown below: –

Finally, we have completed the “Permanent Access Token Step” and it’s time to move ahead to the next step!! But we know that “Too many cooks spoil the broth”, so its time to take a pause and wait for the next step in the upcoming blog

. For more updates, do not forget to Subscribe to our Youtube Channel. Till next time, take care and be well

.

--

--

AMIT SINGH

Software Developer by day & YouTube by night. Salesforce Architect || Salesforce MVP || Integration Expert