2. Generate Permanent Access Token for WhatsApp
- From the sidebar, click on the WhatsApp Section. Within this WhatsApp section, click on Getting Started option. Here, you will be able to find all the details that you have setup 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 task, it’s better to Generate Permanent Access Token.
Initializing Permanent Access Token Generation
- To begin the process of Permanent Access Token generation, Click on Configuration option under WhatsApp section. In the Configuration section, you will see an option called Permanent Token. Click on Learn how to create permanent token link which will redirect you to 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. Now, the next step we need to perform is to generate an access token. For this, click on the first link under an access token section.
- 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 Steps to add new system user section. Click on the first step 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 Users section. Click on Add button. A pop up will appear stating Non-discrimination policy. Leave all the options as it is and click on I accept button. After that another pop up will appear asking you to Create System User.
- 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 as it is and click on 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 Accounts section from the sidebar. Here, you will find an option named WhatsApp Account. Click on WhatsApp Account option to add newly created System User.
- Click on Add People button. Now, it will show all the users that you have created. From the list, you need to select 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 System User Process.
Adding newly created to your app
- Also, we need to add System User to the demo app that we have. To achieve this, scroll down to Accounts section from the sidebar. Here, you will find an option named Apps. Click on Apps option to add newly created System User. Click on Add People button. Now, it will show all the users that you have created. From the list, you need to select 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 System User Process.
Generating Permanent Access Token
- From the Sidebar, scroll up to Users section. Click on System Users option under Users section, select recently created System User and then click on Generate New Token.
- Once you click on Generate New Token, a pop up will appear asking you to select your Demo app. Select your demo app and assign two important permissions for this Demo App which is Whatsapp_business_messaging and Whatsapp_business_management.
- After this, click on Generate Token button which will appear at the bottom of this popup. After this, Permanent Access Token will get generated. For safer side, it will be better to copy and paste the Token on your Notepad as it won’t be stored at Facebook.
Using Postman to send messages to WhatsApp
- Go to developers.facebook.com then My Apps. Select the demo app that you have created Now, scroll down to WhatsApp section from sidebar. Select Getting Started option under WhatsApp section. In the Send and Receive Messages section, select your WhatsApp number in the To section. After this, come down to Send messages with the API section, copy the newly generated command and paste it on your notepad.
- Since, we are going to send messages to WhatsApp through Postman, it’s highly advised to download & install Postman. Once you have installed Postman, go ahead and open the Postman App and click on 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 Continue button and then on Import button. So, this will generate a request for you.
- Now, the basic need of using Postman is to send message. So below this URL, you will find an option named Body. Go to that option, then click on Beautify. This will show you that message that will be sent. Next, click on Headers option. Under Headers, you will find two keys:
Authorization: – This contains the Temporary Access Token (which will expire within 23 hours). Here you need to replace it with Permanent Access Token. For that, remove everything from the Authorization and then type Bearer, give a space and paste the Permanent Access Token that you have saved in your Notepad.
Content – Type
Now, go ahead and click on Send Button next to the URL. This will send message to the mentioned WhatsApp number, and you can also see the confirmation message in the body section of the Postman as shown below.