Connect with us

FACEBOOK

Using QR Codes and Short Links with the WhatsApp Business Platform

Published

on

using-qr-codes-and-short-links-with-the-whatsapp-business-platform

QR codes are an easy way to embed information-dense items into a small image. We frequently see them used for a variety of different purposes, from giving poster-viewers more information to providing diners with the menu at a restaurant.

On a fundamental level, QR codes and short links — a shortened, more readable version of a complex link — are a straightforward, accessible way of connecting with your customer. WhatsApp uses QR codes and short links to help you connect with your customers better. Together these enable your customers to initiate a conversation with you without having to input a phone number or quickly access product information, promotions, and more.

This article will demonstrate how to generate and utilize both QR codes and short links from the WhatsApp Business Platform using the Cloud API, hosted by Meta. We’ll review creating, updating, getting, and deleting a new QR code and short link and show how to send them in a WhatsApp message. You can check out the full code here, at any time.

Prerequisites

To follow this tutorial, you’ll need the following:

  1. A WhatsApp app in your Meta Developer account as per the Getting Started guide and be able to send a test message (webhook setup is not required).

  2. A system user access token with the required permissions (whatsapp_business_management, whatsapp_business_messaging, and business_management)

  3. Basic knowledge of Node.js and Express.js

Additionally, this tutorial will use several Node.js libraries — including dotenv to store the necessary configuration to make HTTP requests with the Cloud API. You’ll also use Postman to test this application’s endpoints. Finally, you’ll need this boilerplate code as the foundation for this article.

Advertisement
free widgets for website

Set Up the Environment

Create and open an .env file at the root of the project and fill in all the missing variables with the values from prerequisite steps 1 and 2.

# Your WhatsApp Business app Id APP_ID=  # Your WhatsApp Business app secret APP_SECRET=  # Recipient phone number without "+" symbol RECIPIENT_PHONE_NUMBER=  # Your WhatsApp phone number Id PHONE_NUMBER_ID=  # Business Account Id BUSINESS_ACCOUNT_ID=  # System User Access Token. Not temporary access token ACCESS_TOKEN=  # Cloud API version number VERSION=v15.0  # Override the default app listener port. LISTENER_PORT=3000

Now that you’ve added the environment variables, start the application using the shortcut script npm init, which will create a skeleton application.

Creating a New QR Code and Short Link

You’ll begin by creating a new QR code and short link using the Business Management API — part of the WhatsApp Business Platform.

Per the documentation, start by sending a POST request to /{phone-number-ID}/message_qrdls endpoint with three query parameters: prefilled_message, generate_qr_image, and your access_token.

Here, you want the scanned QR code and short link to store to prefilled_message. This will allow a user to send you a pre-written message, which can be useful for customer care, e-commerce, obtaining an opt-in to marketing messages, and more.

Advertisement
free widgets for website

Then, generate_qr_image enables you to support two formats for the generated QR code image: .svg or .png. You can select your preferred format using the following method. This example uses .png.

Using the boilerplate, navigate to controllers/qrCode.js and update the createQRCode method with the following code:

const qrdlObject =   {     "prefilled_message" : message,     "generate_qr_image" : type   }    const config =   {     "method" : "post",     "url" : `https://graph.facebook.com/${process.env.VERSION}/${process.env.BUSINESS_ACCOUNT_ID}/message_qrdls`,     "headers" : {       Authorization: `Bearer ${process.env.ACCESS_TOKEN}`,       'Content-Type': 'application/json'     },     "data" : qrdlObject,   };    try   {     await axios( config );   }   catch( error )   {     console.log( "")   }      },     function (err, resp, body) {       if (err) {         console.log("Error!");       } else {         res.json(JSON.parse(body));       }     }   ); };

Then, you need to pass two variables from the request body: a message (which later on will be used as prefilled_message) and your image format. Then, test it using Postman.

Here’s what the request body looks like:

{     "message":"Creating the example QR Code and Short Link",     "type":"png" }

When you hit the Send button in the upper right corner, the API will return the response shown in the screenshot below. The response includes deep_link_url, which acts as a short link, and qr_image_url, which acts as a QR code image. It also contains the id and prefilled_message.

Advertisement
free widgets for website

Sending a WhatsApp Message with a QR Code and Short Link

Next, you’ll be able to send your newly generated QR code and short link to a customer. For that, you need to use the Cloud API. You can follow the examples in that documentation as a reference point. With the API, you’ll be able to send a short link as a text message and an image URL as a media message.

Text Messages

curl -X  POST   'https://graph.facebook.com/v15.0/BUSINESS_ACCOUNT_ID/messages'   -H 'Authorization: Bearer ACCESS_TOKEN'   -d '{   "messaging_product": "whatsapp",   "recipient_type": "individual",   "to": "RECIPIENT_PHONE_NUMBER",   "type": "text",   "text": { // the text object     "preview_url": false,   "body": "MESSAGE_CONTENT"   } }'

Media Messages

curl -X  POST   'https://graph.facebook.com/v15.0/BUSINESS_ACCOUNT_ID/messages'   -H 'Authorization: Bearer ACCESS_TOKEN'   -d '{   "messaging_product": "whatsapp",   "recipient_type": "individual",   "to": "RECIPIENT_PHONE_NUMBER",   "type": "image",   "image": {   "id" : "MEDIA_OBJECT_ID"   } }'

You’ll create a method that accepts a similar request object and performs the HTTP request, which will call the /phone_number_id/messages endpoint and send a message. In controllers/qrCode.js, create a sendMessage method with the following code. The shell method will already be in the boilerplate.

exports.sendMessage = async (req, res) => {   const { to, type } = req.body;   if (!to || !type) {     return res.status(400).json({       error: "Required Fields: to and type",     });   }   request.post(     {       url: `https://graph.facebook.com/${process.env.VERSION}/${process.env.BUSINESS_ACCOUNT_ID}/messages`,       headers: {         Authorization: `Bearer ${process.env.ACCESS_TOKEN}`,         "content-type": "application/json",       },       body: JSON.stringify(req.body),     },     function (err, resp, body) {       if (err) {         console.log("Error!");       } else {         res.json(JSON.parse(body));       }     }   ); };

Next, you’ll send a message with the newly generated QR code. Copy the qr_image_url and add it as an image link to the request body.

The following is how the Postman request object looks. Here, PHONE_NUMBER_TO_SEND can be any dialable format.

{     "messaging_product": "whatsapp",     "recipient_type": "individual",     "to": "RECIPIENT_PHONE_NUMBER",     "type": "image",     "image": {         "link": "https://scontent.fybz2-1.fna.fbcdn.net/m1/v/t6/An95lHumHOGcQ_Fl8cDwVrARmc9T9tmtMLyeTOeSFny-OoLLAqSFHEd8gQzAYVsVS6jNm9IBVU27fcb1H05ERwyb5i87Jtp4fjsNppvFnTu26k7ss_dN8S1ZtkSl6XRZtwB68GUabG8?ccb=10-5&oh=00_AT-LCjyu6J8kkeoW1Qj2rxMZikjrHw0fvwA2C6cn9DYkEA&oe=62C8EC07&_nc_sid=f36290"     } }

If you get a similar response to the image below, the message is sent successfully.

Advertisement
free widgets for website

The image below shows the recipient’s view of the message:

Now, when someone scans this QR code using a smartphone or any other device, it will prefill the message without the user’s input and initiate a new conversation.

Retrieving the List of Existing QR Codes and Short Links

Getting the list of existing QR codes and short links is straightforward, as you only need to make a GET request to the /{phone-number-ID}/message_qrdls endpoint. It returns an array of objects, where individual objects include code(id), prefilled_message, and deep_link_url.

In the controllers/qrCode.js file, update the method with the code below:

exports.fetchQRCodes = async (req, res) => {   request.get(     {       url: `https://graph.facebook.com/${process.env.VERSION}/${process.env.BUSINESS_ACCOUNT_ID}/message_qrdls`,       headers: {         Authorization: `Bearer ${process.env.ACCESS_TOKEN}`       }     },     function (err, resp, body) {       if (err) {         console.log("Error!");       } else {         res.json(JSON.parse(body));       }     }   ); };

After adding the code, test the API with Postman. The below image shows how the request looks in Postman:

Advertisement
free widgets for website

The successful response gives an array of QR codes and short links.

Updating QR Code Messages

Updating a QR code is really helpful, as it updates the message without changing the QR code image. So, you don’t need to reprint or reshare new QR codes. This feature is particularly useful when storing information such as contact and promotional details in QR codes.

To update the QR Code message, you need to know the code(id) of the created QR code, which you can pass as a query parameter to the /{BUSINESS_ACCOUNT_ID}/message_qrdls/{qr-code-id} endpoint.

In the controllers/qrCode.js file, update the method updateQRCode with the following code:

exports.updateQRCode = async (req, res) => {   const { message, qr-code-id } = req.body;   if (!message || !qr-code-id) {     return res.status(400).json({       error: "Required Fields: message and id",     });   }   request.post(     {       url: `https://graph.facebook.com/v14.0/${process.env.META_PHONE_ID}/message_qrdls/${qr-code-id}?prefilled_message=${message}`,       headers: {         Authorization: `Bearer ${process.env.ACCESS_TOKEN}`,         "content-type": "application/json",       }     },     function (err, resp, body) {       if (err) {         console.log("Error!");       } else {         res.json(JSON.parse(body));       }     }   ); };

When you test this in Postman, you’ll see this request object:

Advertisement
free widgets for website
{     "message":"This is my first Updated QR code",     "id":"4WW67TGNCGPXB1" }

The successful request sends back the updated code.

Deleting QR Codes

As QR codes don’t expire, you may want to delete it when the information inside that QR code is either outdated or no longer valid.

First, you’ll need to send a DELETE request to the /{BUSINESS_ACCOUNT_ID}/message_qrdls/{qr-code-id} endpoint.

Navigate to controllers/qrCode.js and update deleteQRCode method from the shell method using the following code:

exports.deleteQRCode = async (req, res) => {   const { qr_code_id } = req.query;   request.delete(     {       url: `https://graph.facebook.com/${process.env.VERSION}/${process.env.BUSINESS_ACCOUNT_ID}/message_qrdls/${qr_code_id}`,       headers: {         Authorization: `Bearer ${process.env.ACCESS_TOKEN}`       }       },     function (err, resp, body) {       if (err) {         console.log("Error!");       } else {         res.json(JSON.parse(body));       }     }   ); };

Here, you’re passing the code id of the QR code you want to retire as query parameters. The successful response outputs a JSON object with success set to true.

Advertisement
free widgets for website

It’s worth noting that once the QR code is deleted, you can no longer use that to initiate a conversation and type a message without the user’s input.

Conclusion

In this hands-on tutorial, you learned how to create, update, fetch, and delete QR codes and short links with the WhatsApp Business Platform using the Cloud API, hosted by Meta – along with a brief look at several use cases.

WhatsApp QR codes are easy to manage and can significantly help increase engagement with your customers in a number of meaningful ways. With WhatsApp’s QR code and short link capabilities, it’s easier than ever before to stay connected with your user base.

First seen at developers.facebook.com

Advertisement
free widgets for website
See also  Facebook users' phone numbers are for sale through a Telegram bot
Continue Reading
Advertisement free widgets for website
Click to comment

Leave a Reply

Your email address will not be published.

FACEBOOK

Enabling developers to create innovative AIs on Messenger and WhatsApp

Published

on

By

enabling-developers-to-create-innovative-ais-on-messenger-and-whatsapp

Every week over 1 billion people connect with businesses on our messaging apps. Many of these conversations are made possible by the thousands of developers who build innovative and engaging experiences on Messenger, Instagram and WhatsApp.

Since opening access to our Llama family of large language models, we’ve seen lots of momentum and innovation with more than 30 million downloads to date. As our messaging services continue to evolve, we believe the technology from Llama and other generative AI models have the potential to enhance business messaging through more natural, conversational experiences.

At Connect Meta announced that developers will be able to build third-party AIs – a term we use to refer to our generative AI-powered assistants – for our messaging services.

We’re making it easy for any developer to get started, so we’re simplifying the developer onboarding process and providing access to APIs for AIs that make it possible to build new conversational experiences within our messaging apps.

All developers will be able to access the new onboarding experience and features on Messenger in the coming weeks. For WhatsApp, we’ll be opening a Beta program in November – if you’re interested in participating please sign up to the waitlist here to learn more.

Advertisement
free widgets for website

We’ll keep everyone updated as we make these tools available to more developers later this year. We look forward to your feedback and seeing what you create.

First seen at developers.facebook.com

See also  Amazon rainforest plots sold via Facebook Marketplace ads
Continue Reading

FACEBOOK

Introducing Facebook Graph API v18.0 and Marketing API v18.0

Published

on

By

introducing-facebook-graph-api-v180-and-marketing-api-v18.0

Today, we are releasing Facebook Graph API v18.0 and Marketing API v18.0. As part of this release, we are highlighting changes below that we believe are relevant to parts of our developer community. These changes include announcements, product updates, and notifications on deprecations that we believe are relevant to your application(s)’ integration with our platform.

For a complete list of all changes and their details, please visit our changelog.

General Updates

Consolidation of Audience Location Status Options for Location Targeting

As previously announced in May 2023, we have consolidated Audience Location Status to our current default option of “People living in or recently in this location” when choosing the type of audience to reach within their Location Targeting selections. This update reflects a consolidation of other previously available options and removal of our “People traveling in this location” option.

We are making this change as part of our ongoing efforts to deliver more value to businesses, simplify our ads system, and streamline our targeting options in order to increase performance efficiency and remove options that have low usage.

This update will apply to new or duplicated campaigns. Existing campaigns created prior to launch will not be entered in this new experience unless they are in draft mode or duplicated.

Advertisement
free widgets for website

Add “add_security_recommendation” and “code_expiration_minutes” to WA Message Templates API

Earlier this year, we released WhatsApp’s authentication solution which enabled creating and sending authentication templates with native buttons and preset authentication messages. With the release of Graph API v18, we’re making improvements to the retrieval of authentication templates, making the end-to-end authentication template process easier for BSPs and businesses.

With Graph API v18, BSPs and businesses can have better visibility into preset authentication message template content after creation. Specifically, payloads will return preset content configuration options, in addition to the text used by WhatsApp. This improvement can enable BSPs and businesses to build “edit” UIs for authentication templates that can be constructed on top of the API.

See also  Delhi HC verdict on WhatsApp, Facebook pleas against CCI order likely tomorrow

Note that errors may occur when upgrading to Graph API v18 if BSPs or businesses are taking the entire response from the GET request and providing it back to the POST request to update templates. To resolve, the body/header/footer text fields should be dropped before passing back into the API.

Re-launching dev docs and changelogs for creating Call Ads

  • Facebook Reels Placement for Call Ads

    Meta is releasing the ability to deliver Call Ads through the Facebook Reels platform. Call ads allow users to call businesses in the moment of consideration when they view an ad, and help businesses drive more complex discussions with interested users. This is an opportunity for businesses to advertise with call ads based on peoples’ real-time behavior on Facebook. Under the Ad set Level within Ads Manager, businesses can choose to add “Facebook Reels” Under the Placements section.
  • Re-Launching Call Ads via API

    On September 12, 2023, we’re providing updated guidance on how to create Call Ads via the API. We are introducing documentation solely for Call Ads, so that 3P developers can more easily create Call Ads’ campaigns and know how to view insights about their ongoing call ad campaigns, including call-related metrics. In the future, we also plan to support Call Add-ons via our API platform. Developers should have access to the general permissions necessary to create general ads in order to create Call Ads via the API platform.

    Please refer to developer documentation for additional information.

Deprecations & Breaking Changes

Graph API changes for user granular permission feature

We are updating two graph API endpoints for WhatsAppBusinessAccount. These endpoints are as follows:

  • Retrieve message templates associated with WhatsAppBusiness Account
  • Retrieve phone numbers associated with WhatsAppBusiness Account

With v18, we are rolling out a new feature “user granular permission”. All existing users who are already added to WhatsAppBusinessAccount will be backfilled and will continue to have access (no impact).

The admin has the flexibility to change these permissions. If the admin changes the permission and removes access to view message templates or phone numbers for one of their users, that specific user will start getting an error message saying you do not have permission to view message templates or phone numbers on all versions v18 and older.

Advertisement
free widgets for website

Deprecate legacy metrics naming for IG Media and User Insights

Starting on September 12, Instagram will remove duplicative and legacy, insights metrics from the Instagram Graph API in order to share a single source of metrics to our developers.

This new upgrade reduces any confusion as well as increases the reliability and quality of our reporting.

After 90 days of this launch (i.e. December 11, 2023), we will remove all these duplicative and legacy insights metrics from the Instagram Graph API on all versions in order to be more consistent with the Instagram app.

We appreciate all the feedback that we’ve received from our developer community, and look forward to continuing to work together.

Please review the media insights and user insights developer documentation to learn more.

Advertisement
free widgets for website

Deprecate all Facebook Wi-Fi v1 and Facebook Wi-Fi v2 endpoints

Facebook Wi-Fi was designed to improve the experience of connecting to Wi-Fi hotspots at businesses. It allowed a merchant’s customers to get free Wi-Fi simply by checking in on Facebook. It also allowed merchants to control who could use their Wi-Fi and for how long, and integrated with ads to enable targeting to customers who had used the merchant’s Wi-Fi. This product was deprecated on June 12, 2023. As the partner notice period has ended, all endpoints used by Facebook Wi-Fi v1 and Facebook Wi-Fi v2 have been deprecated and removed.

API Version Deprecations:

As part of Facebook’s versioning schedule for Graph API and Marketing API, please note the upcoming deprecations:

Graph API

  • September 14, 2023: Graph API v11.0 will be deprecated and removed from the platform
  • February 8, 2024: Graph API v12.0 will be deprecated and removed from the platform
  • May 28, 2024: Graph API v13.0 will be deprecated and removed from the platform

Marketing API

  • September 20, 2023: Marketing API v14.0 will be deprecated and removed from the platform
  • September 20, 2023: Marketing API v15.0 will be deprecated and removed from the platform
  • February 06, 2024: Marketing API v16.0 will be deprecated and removed from the platform

To avoid disruption to your business, we recommend migrating all calls to the latest API version that launched today.

Facebook Platform SDK

As part of our 2-year deprecation schedule for Platform SDKs, please note the upcoming deprecations and sunsets:

  • October 2023: Facebook Platform SDK v11.0 or below will be sunset
  • February 2024: Facebook Platform SDK v12.0 or below will be sunset

First seen at developers.facebook.com

See also  Facebook India's Avinash Pant on finding the winning strategy for its biggest audience
Continue Reading

FACEBOOK

Allowing Users to Promote Stories as Ads (via Marketing API)

Published

on

By

allowing-users-to-promote-stories-as-ads-(via-marketing-api)

Before today (August 28, 2023), advertisers could not promote images and/or videos used in Instagram Stories as ads via the Instagram Marketing API. This process created unwanted friction for our partners and their customers.

After consistently hearing about this pain point from our developer community, we have removed this unwanted friction for advertisers and now allow users to seamlessly promote their image and/or video media used in Instagram Stories as ads via the Instagram Marketing API as of August 28, 2023.

We appreciate all the feedback received from our developer community, and hope to continue improving your experience.

Please review the developer documentation to learn more.

First seen at developers.facebook.com

Advertisement
free widgets for website
See also  Apple to roll out new privacy update; Facebook, Google protest
Continue Reading

Trending