Positus EN
PositusFree trialPTES
  • WhatsApp Business API
  • WhatsApp Benchmark
  • API - Documentation
  • Code Samples
  • Webhook
  • Language
  • Português
  • Spanish
  • Sites
  • Website Positus
  • Status Page
  • Support
  • Brand guidelines
  • Robbu Group
Powered by GitBook
On this page
  • Postman file
  • Code Samples

Was this helpful?

Code Samples

See some code samples to integrate your API.

PreviousAPI - DocumentationNextWebhook

Last updated 4 years ago

Was this helpful?

Postman file

Postman is a tool that aims to test RESTful services (Web APIs) by sending HTTP requests and analyzing their feedback.

Production You should use the following URL:

Once hiring and activating your WhatsApp Business API account, we will provide a media_id by number and you will be able to generate your tokens through the platform.

Development You should use the following URL:

Create your sandbox account through the link and generate a token following the instructions on the screen. Navigate to the "webhook" menu and copy the POST URL in it, this one uses "Key". In the development environment you will not be able to send HSM messages, but all other resources are available for sending and receiving.

Code Samples

C# - RestSharp

var client = new RestClient("https://api.positus.global/v2/sandbox/whatsapp/numbers/{{chave}}/messages");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "Bearer xxxx");
request.AddParameter("application/json,text/plain", "{\r\n  \"to\": \"+5511999999999\",\r\n  \"type\": \"text\",\r\n  \"text\": {\r\n      \"body\": \"your-message-content\"\r\n  }\r\n}",  ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

PHP - cURL

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.positus.global/v2/sandbox/whatsapp/numbers/{{chave}}/messages",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS =>"{\r\n  \"to\": \"+5511999999999\",\r\n  \"type\": \"text\",\r\n  \"text\": {\r\n      \"body\": \"your-message-content\"\r\n  }\r\n}",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/json",
    "Authorization: Bearer xxxx"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Python - http.client

import http.client
import mimetypes
conn = http.client.HTTPSConnection("api.positus.global")
payload = "{\r\n  \"to\": \"+5511999999999\",\r\n  \"type\": \"text\",\r\n  \"text\": {\r\n      \"body\": \"your-message-content\"\r\n  }\r\n}"
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer xxxx'
}
conn.request("POST", "/v2/sandbox/whatsapp/numbers/{{chave}}/messages", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

Nodejs - Request

var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://api.positus.global/v2/sandbox/whatsapp/numbers/{{chave}}/messages',
  'headers': {
    'Content-Type': ['application/json'],
    'Authorization': 'Bearer xxxx'
  },
  body: "{\r\n  \"to\": \"+55119999999999\",\r\n  \"type\": \"text\",\r\n  \"text\": {\r\n      \"body\": \"your-message-content\"\r\n  }\r\n}"

};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});

JavaScript - JQuery

var settings = {
  "url": "https://api.positus.global/v2/sandbox/whatsapp/numbers/{{chave}}/messages",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": ["application/json"],
    "Authorization": "Bearer xxxx"
  },
  "data": "{\r\n  \"to\": \"+55119999999999\",\r\n  \"type\": \"text\",\r\n  \"text\": {\r\n      \"body\": \"your-message-content\"\r\n  }\r\n}",
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

PowerShelll - RestMethod

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("Authorization", "Bearer xxxx")

$body = "{
`n  `"to`": `"+55119999999999`",
`n  `"type`": `"text`",
`n  `"text`": {
`n      `"body`": `"your-message-content`"
`n  }
`n}"

$response = Invoke-RestMethod 'https://api.positus.global/v2/sandbox/whatsapp/numbers/{{chave}}/messages' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

Go - Native

package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.positus.global/v2/sandbox/messages"
  method := "POST"

  payload := strings.NewReader("{
\n  \"to\": \"+55119999999999\",
\n  \"type\": \"text\",
\n  \"text\": {
\n      \"body\": \"your-message-content\"
\n  }
\n}")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("Content-Type", "application/json")
  req.Header.Add("Authorization", "Bearer xxxx")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}

Download Postman App
https://api.positus.global/v2/whatsapp/numbers/{{chave}}/messages
https://api.positus.global/v2/sandbox/whatsapp/numbers/{{chave}}/messages
https://studio.posit.us/
32KB
Positus API (October 2020).postman_collection.json
API for production
9KB
Positus API Sandbox (November 2020).postman_collection.json
API for development SandBox