Here is a VB.NET code snippet to determine the availability of Whatsapp by phone number.
The checker_data.json file specifies the token to work with whapi.cloud, and the number to check.
<pre>Imports System.Net.Http
Imports Newtonsoft.Json.Linq
Module Program
Sub Main()
Dim dataFile = JObject.Parse(IO.File.ReadAllText("checker_data.json"))
Dim phone As String = dataFile("phone").ToString()
Dim token As String = dataFile("token").ToString()
If String.IsNullOrEmpty(phone) Then
Console.WriteLine("Phone is empty")
Return
End If
If String.IsNullOrEmpty(token) Then
Console.WriteLine("Token is empty")
Return
End If
Dim client As New HttpClient()
client.DefaultRequestHeaders.Add("accept", "application/json")
client.DefaultRequestHeaders.Add("content-type", "application/json")
client.DefaultRequestHeaders.Add("authorization", $"Bearer {token}")
Dim payload As New JObject(
New JProperty("blocking", "no_wait"),
New JProperty("force_check", False),
New JProperty("contacts", New JArray(phone))
)
Dim response As HttpResponseMessage = client.PostAsync("https://gate.whapi.cloud/contacts", New StringContent(payload.ToString(), Text.Encoding.UTF8, "application/json")).Result
If response.IsSuccessStatusCode Then
Dim jsonResponse = JObject.Parse(response.Content.ReadAsStringAsync().Result)
Dim contacts = jsonResponse("contacts")
If contacts IsNot Nothing AndAlso contacts.Count > 0 Then
Dim status = contacts(0)("status").ToString()
If status = "valid" Then
Console.WriteLine("Phone exists")
Else
Console.WriteLine("Phone doesn't exist")
End If
Else
Console.WriteLine("Check your checker_data file")
End If
Else
Console.WriteLine($"Failed to check. Status Code: {response.StatusCode}")
End If
End Sub
End Module
Other methods for automation can be found in whatsapp API documentation:
WhatsApp API Documentation | Gateway for developers[
^]