> For the complete documentation index, see [llms.txt](https://docs.es.posit.us/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.es.posit.us/exemplos-de-codigos.md).

# Ejemplos de códigos

## Postman file

*Postman es una herramienta que tiene como objetivo probar los servicios RESTful (API web) enviando solicitudes HTTP y analizando sus comentarios.* \
[Descargar la aplicación Postman](https://www.postman.com/downloads/)

{% hint style="success" %}
**Producción**\
Debe usar la siguiente URL:\
<https://api.positus.global/v2/whatsapp/numbers/{{chave}}/messages>

Al contratar y activar su cuenta de API empresarial de WhatsApp, le proporcionaremos un número de media\_id y podrá generar sus tokens a través de la plataform&#x61;*.*
{% endhint %}

{% file src="/files/-MKodWFxEgEaSdPVNCJD" %}
API for production
{% endfile %}

{% hint style="info" %}
**Desarrollo**\
Debe usar la siguiente URL:\
<https://api.positus.global/v2/sandbox/whatsapp/numbers/{{chave}}/messages><br>

Crea tu cuenta sandbox a través del enlace <https://studio.posit.us/> y genera un token siguiendo las instrucciones en pantalla. Navegue hasta el menú "webhook" y copie la URL POST en él, este usa "Clave". En el entorno de desarrollo, no podrá enviar mensajes HSM, pero todos los demás recursos están disponibles para enviar y recibir.
{% endhint %}

{% file src="/files/-MLmCWqi29iLjMwzHb2V" %}
API for development SandBox
{% endfile %}

## Ejemplos de códigos

{% tabs %}
{% tab title=".NET" %}

## C# - RestSharp

```csharp
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);
```

{% endtab %}

{% tab title="PHP" %}

## PHP - cURL

```php
<?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;

```

{% endtab %}

{% tab title="PYTHON" %}

## Python - http.client

```python
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"))
```

{% endtab %}

{% tab title="NODEJS" %}

## Nodejs - Request

```javascript
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);
});

```

{% endtab %}

{% tab title="JAVASCRIPT" %}

## JavaScript - JQuery

```javascript
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);
});
```

{% endtab %}

{% tab title="POWESHELL" %}

## PowerShelll - RestMethod

```d
$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
```

{% endtab %}

{% tab title="GO" %}

## 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))
}
```

{% endtab %}
{% endtabs %}

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.es.posit.us/exemplos-de-codigos.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
