Send Automated WhatsApp Messages Using Powershell The Ultimate Guide

November 27, 2024

Today, we’ll show you the ultimate guide to sending different types of WhatsApp messages using PowerShell

Effective communication is vital for project coordination, community engagement, and responsive customer support. Wassenger enhances this process by providing seamless management and interaction tools within WhatsApp messages. With its intuitive API and automation features, sending messages, videos, images, documents, and voice memos becomes simple and efficient.

In this article you will find:

  • Send Image Message with Powershell
  • Send Video Messages with Powershell
  • Send Document Messages with Powershell
  • Send Audio Voice Record with Powershell
  • Send a Media Message with an Uploaded File Using Powershell
  • Send a GIF Message with Powershell
  • Send a Poll Message with Powershell
  • Send a Scheduled Date and Time Message with Powershell
  • Send Dynamic Native Button Messages with Powershell
  • Send a List of Items to Select From with Powershell
  • Send a Message with Text Formatting Using Powershell
  • Send a Location Message with Coordinates Using Powershell
  • Send a Location Message with the Address Using Powershell
  • Send a Message with Variables Using Powershell
  • Send Messages with Links Using Powershell
  • Send Contact Card Messages with Powershell
  • Reply to a Message with Powershell
  • Forward a Message with Powershell
  • Send a Catalogue Message with Powershell
  • Send a Message in Real-Time with No Enqueueing Using Powershell
  • Send a Message with Maximum Retries Using Powershell
  • Send a Message with the Expiration Time Using Powershell
  • Send a Message Within a Time and Day Range Using Powershell
  • Send a Message Reaction Using Powershell
  • Remove a Message Reaction Using Powershell
  • Send a Message on Behalf of an Agent and Assign a Chat Using Powershell
  • Send a Message and Resolve the Chat with Powershell
  • Send a Message and Add a Chat Label with Powershell

🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and getting started in minutes!

Requirements

  • To have a WhatsApp number already linked to the platform and online.
  • Message recipient phone number with international prefix in E164 format. Example: +12345678900. Validate the phone number format here.

API endpoint

We will use the following API endpoint to send messages to a group:

Prepare the request

Target API URL using the POST method

https://api.wassenger.com/v1/messages

Required HTTPS headers > Obtain your API key here

Content-Type: application/json
Token: $API_TOKEN

Use body in JSON format

{
  "phone": "+1234567890",
  "message": "Hello world, this is a sample message"
}

🖥️ Looking for a code example? Go to the API live tester and get ready-to-use code examples in 15+ programming languages, including Python, JavaScript, PHP, C#, Java, Ruby, Go, Powershell, cURL and more.

Send text messages with Powershell

# Define the API endpoint $apiUrl = 'https://api.wassenger.com/v1/messages'

# Set up the request headers $headers = @{ "Content-Type" = "application/json" "Token" = "ENTER API KEY HERE" }

# Create the request body $body = @{ phone = "+1234567890" message = "Hello world, this is a sample message" } | ConvertTo-Json -Depth 10

# Send the POST request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $body

🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

More examples for group messages with Powershell

For full samples, visit our API Live Tester

Send image message with Powershell

# Define the API endpoint and headers $apiUrl = 'https://api.wassenger.com/v1/messages' $headers = @{ "Content-Type" = "application/json" # Specify JSON format "Token" = "ENTER API KEY HERE" # Replace with your API token }

# Construct the message body as a hashtable $messageBody = @{ phone = "+1234567890" # Recipient's phone number message = "This is a caption for an image message" media = @{ url = "https://picsum.photos/seed/picsum/600/400" expiration = "7d" viewOnce = $false } } | ConvertTo-Json -Depth 2 # Convert to JSON format for API compatibility

# Send the POST request $response = Invoke-WebRequest ` -Uri $apiUrl ` -Method POST ` -Headers $headers ` -ContentType 'application/json' ` -Body $messageBody

# Output the response for debugging or logging $response.Content

Send video messages with Powershell

# Define the API endpoint and headers $apiUrl = 'https://api.wassenger.com/v1/messages' $headers = @{ "Content-Type" = "application/json" # Specify JSON format "Token" = "ENTER API KEY HERE" # Replace with your API token }

# Construct the message body as a hashtable $messageBody = @{ phone = "+1234567890" # Recipient's phone number message = "This is a caption for a video message" # Text of the message media = @{ url = "https://download.samplelib.com/mp4/sample-5s.mp4" # URL to the video file expiration = "7d" # Media expiration in days } } | ConvertTo-Json -Depth 2 # Convert to JSON format for API compatibility

# Send the POST request $response = Invoke-WebRequest ` -Uri $apiUrl ` -Method POST ` -Headers $headers ` -ContentType 'application/json' ` -Body $messageBody

# Output the response for debugging or logging $response.Content

Send document messages with Powershell

# Define constants $apiUrl = 'https://api.wassenger.com/v1/messages' $phoneNumber = "+1234567890" $headers = @{ "Content-Type" = "application/json" "Token" = "ENTER API KEY HERE" }

# Define payload $payload = @{ phone = $phoneNumber media = @{ url = "https://www.africau.edu/images/default/sample.pdf" expiration = "30d" } } | ConvertTo-Json -Depth 2

# Send request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send audio voice record with Powershell

# Define payload for sending an audio message $payload = @{ phone = $phoneNumber media = @{ url = "https://download.samplelib.com/mp3/sample-9s.mp3" format = "ptt" # Indicates a voice message } } | ConvertTo-Json -Depth 2

# Send request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.ContentSend audio voice record with Powershell

Send a media message with an uploaded file using Powershell

{{UPLOADED FILE ID}} : Replace this expression with the specific value

  • You can upload the file here
  • The file ID will look something like this: 57443b8773c036f2bae0cd96

# Define constants $apiUrl = 'https://api.wassenger.com/v1/messages' $phoneNumber = "+1234567890" $uploadedFileId = "{{UPLOADED FILE ID}}" # Replace with actual file ID $headers = @{ "Content-Type" = "application/json" "Token" = "ENTER API KEY HERE" }

# Define payload $payload = @{ phone = $phoneNumber message = "This is a caption for an image message" media = @{ file = $uploadedFileId } } | ConvertTo-Json -Depth 2

# Send request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send a GIF message with Powershell

# Define payload for sending a GIF message $payload = @{ phone = $phoneNumber message = "This is a sample caption for a GIF message" media = @{ url = "https://i.giphy.com/vKHKDIdvxvN7vTAEOM.mp4" format = "gif" } } | ConvertTo-Json -Depth 2

# Send request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send a poll message with Powershell

# Define constants $apiUrl = 'https://api.wassenger.com/v1/messages' $phoneNumber = "+1234567890" $headers = @{ "Content-Type" = "application/json" "Token" = "ENTER API KEY HERE" }

# Define payload $payload = @{ phone = $phoneNumber poll = @{ name = "Vote for your favorite color" options = @("Red", "Green", "Blue", "Yellow", "Grey", "Black", "Orange", "Purple", "White") } } | ConvertTo-Json -Depth 2

# Send request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send a scheduled date and time message with Powershell

# Define payload for a scheduled message $payload = @{ phone = $phoneNumber message = "This is a scheduled message to be sent in 10 minutes" deliverAt = "2024-10-21T10:46:24.475Z" # ISO 8601 formatted time } | ConvertTo-Json -Depth 2

# Send request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send dynamic native button messages with Powershell

WhatsApp no longer accepts native button messages. Buttons messages will be automatically converted into raw text equivalent messages. Learn more here

# Define constants $apiUrl = 'https://api.wassenger.com/v1/messages' $phoneNumber = "+1234567890" $headers = @{ "Content-Type" = "application/json" "Token" = "ENTER API KEY HERE" }

# Define payload $payload = @{ phone = $phoneNumber message = "This is a message with dynamic reply buttons" header = "Optional message header" footer = "Optional message footer" buttons = @( @{ id = "id1"; text = "Say hello" }, @{ id = "id2"; text = "Say goodbye" }, @{ id = "id3"; text = "Get help" } ) } | ConvertTo-Json -Depth 2

# Send request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send a list of items to select from with Powershell

WhatsApp no longer accepts list messages. List messages will be automatically converted into raw text equivalent messages. Learn more here

# Define constants $apiUrl = 'https://api.wassenger.com/v1/messages' $phoneNumber = "+1234567890" $headers = @{ "Content-Type" = "application/json" "Token" = "ENTER API KEY HERE" }

# Define payload $payload = @{ phone = $phoneNumber list = @{ button = "Select one option" description = "Select which type of vehicle you are interested in" title = "Motor Business" footer = "Since 1990" sections = @( @{ title = "Select a car type" rows = @( @{ title = "Coupe"; id = "a1"; description = "This a description for coupe cars" }, @{ title = "Sports"; id = "a2"; description = "This a description for sports cars" }, @{ title = "SUV"; id = "a3"; description = "This a description for SUV cars" }, @{ title = "Minivan"; id = "a4"; description = "This a description for minivan cars" }, @{ title = "Crossover"; id = "a5"; description = "This a description for crossover cars" }, @{ title = "Wagon"; id = "a6"; description = "This a description for wagon cars" } ) }, @{ title = "Select a motorbike type" rows = @( @{ title = "Touring"; id = "b1"; description = "Designed to excel at covering long distances" }, @{ title = "Cruiser"; id = "b2"; description = "Harley-Davidsons largely define the cruiser category" }, @{ title = "Standard"; id = "b3"; description = "Motorcycle intended for use on streets and commuting" } ) } ) } } | ConvertTo-Json -Depth 3

# Send request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send a message with text formatting using Powershell

# Define payload for sending a formatted text message $payload = @{ phone = $phoneNumber message = "This message is formatted using _italic format_, *bold format*, strikethrough format and ```monospace format```" } | ConvertTo-Json -Depth 2

# Send request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.ContentSend location message with coordinates using Powershell

Send a message with location coordinates using Powershell

Learn more about how to send location messages with coordinates in this tutorial

# Define payload for sending a location message $payload = @{ phone = $phoneNumber location = @{ coordinates = @(40.7583748, -73.9891184) # Latitude, Longitude } message = "This is a location message using coordinates" } | ConvertTo-Json -Depth 2

# Send request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send location message with address using Powershell

Learn more about how to send location messages with addresses in this tutorial

# Define constants $apiUrl = 'https://api.wassenger.com/v1/messages' $phoneNumber = "+1234567890" $headers = @{ "Content-Type" = "application/json" "Token" = "ENTER API KEY HERE" }

# Define payload $payload = @{ phone = $phoneNumber message = "This is a location message using an address" location = @{ address = "Santa Claus Main Post Office, Tähtikuja 1, 96930 Arctic Circle, Finland" } } | ConvertTo-Json -Depth 2

# Send request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send a message with variables using Powershell

Learn more about how to send messages with template variables in this tutorial.

# Define payload for sending a message with variables $payload = @{ phone = $phoneNumber message = "Dear {{ contact.name | customer }},`nThanks for contacting us!`nWe will answer your query shortly.`n`nYour message was received on {{ date.humanize.full }}" } | ConvertTo-Json -Depth 2

# Send request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.ContentSend messages with links using Powershell

Send a message with a URL using Powershell

Learn more about how to send messages with URL links in this tutorial

# Define constants $apiUrl = 'https://api.wassenger.com/v1/messages' $phoneNumber = "+1234567890" $headers = @{ "Content-Type" = "application/json" "Token" = "ENTER API KEY HERE" }

# Define payload $payload = @{ phone = $phoneNumber message = "Check out this cool link: https://www.youtube.com" } | ConvertTo-Json -Depth 2

# Send the request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

Send contact card messages with Powershell

Learn more about how to send contact card messages in this tutorial

# Define constants $apiUrl = 'https://api.wassenger.com/v1/messages' $apiToken = "ENTER API KEY HERE" $phoneNumber = "+1234567890" $contactName = "John Doe"

# Define headers $headers = @{ "Content-Type" = "application/json" "Token" = $apiToken }

# Define payload $payload = @{ phone = $phoneNumber contacts = @( @{ phone = $phoneNumber name = $contactName } ) } | ConvertTo-Json -Depth 2

# Send the request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Reply to a message with Powershell

{{MESSAGE ID}} : Replace with the actual WhatsApp message ID to forward (18, 20, 22 or 32 hexadecimal value)

# Define constants $apiUrl = 'https://api.wassenger.com/v1/messages' $apiToken = "ENTER API KEY HERE" $phoneNumber = "+1234567890" $messageId = "{{MESSAGE ID}}" # Replace with the actual message ID $replyMessage = "This message is a reply to another message within the same chat"

# Define headers $headers = @{ "Content-Type" = "application/json" "Token" = $apiToken }

# Define payload $payload = @{ phone = $phoneNumber quote = $messageId message = $replyMessage } | ConvertTo-Json -Depth 2

# Send the request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Forward a message with Powershell

{{MESSAGE ID}} : Replace with the actual WhatsApp message ID to reply to (18, 20, 22 or 32 hexadecimal value)

# Define constants $apiUrl = 'https://api.wassenger.com/v1/messages' $apiToken = "ENTER API KEY HERE" $phoneNumber = "+1234567890" $messageId = "{{MESSAGE ID}}" # Replace with the actual message ID $forwardChat = "+1234567890" # Replace with the chat ID where the message will be forwarded $forwardMessage = "The given message by ID will be forwarded to another chat"

# Define headers $headers = @{ "Content-Type" = "application/json" "Token" = $apiToken }

# Define payload $payload = @{ phone = $phoneNumber forward = @{ message = $messageId chat = $forwardChat } message = $forwardMessage } | ConvertTo-Json -Depth 2

# Send the request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $p

Send a catalogue message with Powershell

{{PRODUCT CATALOG ID TO SEND}} : Replace this expression with the specific value

# Define constants $apiUrl = 'https://api.wassenger.com/v1/messages' $apiToken = "ENTER API KEY HERE" $phoneNumber = "+1234567890" $productCatalogId = "{{PRODUCT CATALOG ID TO SEND}}" # Replace with the actual product catalog ID

# Define headers $headers = @{ "Content-Type" = "application/json" "Token" = $apiToken }

# Define payload $payload = @{ phone = $phoneNumber product = $productCatalogId } | ConvertTo-Json -Depth 1

# Send the request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send a message in real-time with no enqueueing using Powershell

# Define constants $apiUrl = 'https://api.wassenger.com/v1/messages' $apiToken = "ENTER API KEY HERE" $phoneNumber = "+1234567890" $messageContent = "This message will be delivered in real-time if the session is online, otherwise the API will return an error"

# Define headers $headers = @{ "Content-Type" = "application/json" "Token" = $apiToken }

# Define payload $payload = @{ live = $true phone = $phoneNumber message = $messageContent } | ConvertTo-Json -Depth 1

# Send the request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send a message with maximum retries using Powershell

# Variables $apiUrl = 'https://api.wassenger.com/v1/messages' $apiToken = "ENTER API KEY HERE" $phoneNumber = "+1234567890" $message = "This message will be retried only twice. If the delivery fails twice, it will be flagged as deleted message, removed from the queue and not delivered"

# Headers $headers = @{ "Content-Type" = "application/json" "Token" = $apiToken }

# Payload $payload = @{ retries = 2 phone = $phoneNumber message = $message } | ConvertTo-Json -Depth 1

# Send Request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send a message with the expiration time using Powershell

# Variables $expirationSeconds = 90 $message = "This message will be deleted if it cannot be delivered within 90 seconds after being queued."

# Payload $payload = @{ expiration = @{ seconds = $expirationSeconds } phone = $phoneNumber message = $message } | ConvertTo-Json -Depth 1

# Send Request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

Send a message within a time and day range using Powershell

# Variables $message = "Restricted message example that will only be delivered between 9 am to 5 pm from Monday to Friday."

# Payload $payload = @{ phone = $phoneNumber message = $message restrict = @{ start = 9 end = 17 timezone = "CEST" weekdays = @(1,2,3,4,5) } } | ConvertTo-Json -Depth 1

# Send Request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send a message reaction using Powershell

{{WHATSAPP MESSAGE ID}} : Replace this expression with the specific value

# Variables $reaction = "👍" $messageId = "{{WHATSAPP MESSAGE ID}}"

# Payload $payload = @{ phone = $phoneNumber reaction = $reaction reactionMessage = $messageId } | ConvertTo-Json -Depth 1

# Send Request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Remove message reaction:

{{WHATSAPP MESSAGE ID}} : Replace this expression with the specific value

# Variables $messageId = "{{MESSAGE WHATSAPP ID}}"

# Payload $payload = @{ phone = $phoneNumber reaction = "-" reactionMessage = $messageId } | ConvertTo-Json -Depth 1

# Send Request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send a message on behalf of an agent and assign a chat using Powershell

{{USER ID}} : Replace with the actual user ID (24 hexadecimal value)

{{ASSIGNED USER ID}} : Replace with the actual user ID to assign the chat (24 hexadecimal value)

# Variables $agentId = "{{USER ID}}" $assignedAgentId = "{{ASSIGNED USER ID}}" $message = "This message is sent via API on behalf of an agent. The chat will also be assigned to the agent after message delivery."

# Payload $payload = @{ phone = $phoneNumber agent = $agentId message = $message actions = @( @{ action = "chat:assign" params = @{ agent = $assignedAgentId } } ) } | ConvertTo-Json -Depth 2

# Send Request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send a message and resolve the chat with Powershell

# Variables $message = "Once this message is delivered, the chat will be reported as unresolved/pending in the web chat interface."

# Payload $payload = @{ phone = $phoneNumber message = $message actions = @( @{ action = "chat:unresolve" } ) } | ConvertTo-Json -Depth 1

# Send Request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

Send a message and add a chat label with Powershell

# Variables $message = "Once this message is delivered, the given labels will be added to the chat automatically." $labels = @("new", "sales")

# Payload $payload = @{ phone = $phoneNumber message = $message actions = @( @{ action = "labels:add" params = @{ labels = $labels } } ) } | ConvertTo-Json -Depth 2

# Send Request $response = Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $payload $response.Content

🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

Live API testing

You can live-test and play with the API directly from your browser in minutes.

Once you are done testing, get the auto-generated code example in your preferred programming language and you will be ready to go.

FAQ

How to send messages to multiple phone numbers

You just have to send multiple API requests, one per target phone number.

For instance, if you want to send a message to 10 phone numbers, you should send 10 independent HTTPS requests to the API.

There is no option to send multiple messages in a single API request.

How to validate if a phone number can receive WhatsApp messages

You can validate if a given phone number is linked to a WhatsApp account and can receive messages.

The API provides an endpoint that can validate whether a given phone number exists in WhatsApp or not.

The only requirement is to have at least one WhatsApp number connected to the platform in your current account.

For more details, please check out the API endpoint documentation here.

Before you check if a phone number exists on WhatsApp, you can also validate and normalize the format of a list of phone numbers by using the numbers validator API endpoint. This endpoint only validates the correct E164 format, but it does not check whether the phone number effectively exists on WhatsApp.

Note: The number of WhatsApp check validations is limited per month based on your subscription plan. Please check out the pricing table for more details about the limits.

Looking for more answers? Check out the extended FAQs.

Further useful resources

API Documentation

For more details about the endpoint API, please check the documentation where you will find all the details about the accepted request params, possible success or error responses and ready-to-use code examples in multiple programming languages:

https://app.wassenger.com/docs/#tag/Messages/operation/createMessage

Ready to transform your WhatsApp communication?

Start automating your customer interactions today with Wassenger

Get Started Free