Criando um webhook para interceptar um Pix via API
Pela Openpix é possível criar webhooks para interceptar quando um pix for realizado. Hoje, há duas maneiras de realizar a criação do mesmo: via plataforma ou API.
Neste tutorial iremos descrever como criar um webhook para interceptar a chegada de um novo Pix via uma chamada API.
Para cadastrar o webhook via API basta seguir nossa especifição para realizar um POST na api de Webhook.
- cURL
 - JavaScript
 
curl --location --request POST 'https://api.openpix.com.br/api/openpix/v1/webhook' \
--header 'Content-Type: application/json' \
--header 'Authorization: <appID>' \
--data-raw '{
    "webhook": {
    "name": "webhook via api",
    "url": "https://minhaurl.test/webhook",
    "authorization": "auth_key",
    "isActive": true
}
}'
const createWebhook = async () => {
  const payload = {
    name: 'webhook via api',
    url: 'https://minhaurl.test/webhook',
    authorization: 'auth_key',
    isActive: true,
  };
  const response = await fetch(
    'https://api.openpix.com.br/api/openpix/v1/webhook',
    {
      method: 'POST',
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
        Authorization: 'appID',
      },
      body: JSON.stringify(payload),
    },
  );
  const data = await response.json();
  console.log({
    data,
  });
};