Criar Webhook
Descrição: Cadastra um gatilho a partir de determinado evento
Endpoint
POST/api/v1/integration/webhooks
Regras
| Atributo | Descrição | Tipo | Obrigatório | Validações |
|---|---|---|---|---|
| webhook_event | Evento que irá gerar o disparo do gatilho | string | Sim | Valores válidos: CREATE_PRODUCER, UPDATE_PRODUCER, DELETE_PRODUCER, CREATE_WAREHOUSE, UPDATE_WAREHOUSE, DELETE_WAREHOUSE, CREATE_FARM, UPDATE_FARM, DELETE_FARM, CREATE_GUEST_USER, UPDATE_GUEST_USER, DELETE_GUEST_USER, CREATE_DELIVERY_PLACE, UPDATE_DELIVERY_PLACE, DELETE_DELIVERY_PLACE, CREATE_ORDER_COMMITMENT, UPDATE_ORDER_COMMITMENT, DELETE_ORDER_COMMITMENT, CREATE_WALLET, UPDATE_WALLET, DELETE_WALLET, UPDATE_WORKFLOW_ORDER_COMMITMENT, CHANGE_PRODUCER_STATUS_ESG, CHANGE_FARM_STATUS_ESG, PRODUCER_PRODUCTION |
| url | URI do cliente que deverá ser acionada quando o evento ocorrer | string | Sim | Ex: https://api.cliente.com/api/v1/receive (Deverá aceitar requisições do tipo POST.) |
| basic_authentication | Se preenchido, utilizaremos essa informação para passar no header via basic auth | string | Não |
Exemplo de Requisição
- cURL
- Java
- JavaScript
- Python
curl -X POST \
-H "Authorization: {SUA_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"webhook_event": "CREATE_FARM",
"url": "https://api.cliente.com/api/v1/receive",
"basic_authentication": "usuário:senha"
}' \
"https://api.merx.tech/api/v1/integration/webhooks"
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
String body = "{"
+ "\"webhook_event\": \"CREATE_FARM\","
+ "\"url\": \"https://api.cliente.com/api/v1/receive\","
+ "\"basic_authentication\": \"usuário:senha\""
+ "}";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.merx.tech/api/v1/integration/webhooks"))
.header("Authorization", "{SUA_API_KEY}")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpClient client = HttpClient.newHttpClient();
try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
} catch (Exception e) {
e.printStackTrace();
}
const response = await fetch(
'https://api.merx.tech/api/v1/integration/webhooks',
{
method: 'POST',
headers: {
'Authorization': '{SUA_API_KEY}',
'Content-Type': 'application/json',
},
body: JSON.stringify({
webhook_event: 'CREATE_FARM',
url: 'https://api.cliente.com/api/v1/receive',
basic_authentication: 'usuário:senha',
}),
}
);
console.log(response.status);
import requests
url = "https://api.merx.tech/api/v1/integration/webhooks"
headers = {
"Authorization": "{SUA_API_KEY}",
"Content-Type": "application/json"
}
payload = {
"webhook_event": "CREATE_FARM",
"url": "https://api.cliente.com/api/v1/receive",
"basic_authentication": "usuário:senha"
}
response = requests.post(url, json=payload, headers=headers)
print(response.status_code)
Parâmetros
Parâmetros de Cabeçalho
| Nome | Descrição | Tipo | Obrigatório |
|---|---|---|---|
| Authorization | Chave de API obtida via support-api@merx.tech | String | Sim |
| Content-Type | application/json | String | Sim |
Parâmetros do Corpo
| Nome | Descrição | Tipo | Obrigatório |
|---|---|---|---|
| webhook_event | Evento que irá gerar o disparo do gatilho | String | Sim |
| url | URI do cliente que deverá ser acionada quando o evento ocorrer | String | Sim |
| basic_authentication | Credencial de autenticação básica para o header da chamada ao cliente (opcional) | String | Não |
Respostas
- 201 - Created
{
"id": "string"
}
- 400 - Bad Request
{
"messages": ["message.entidade.campo-inválido"]
}
401 - Unauthorized
404 - NotFound