Informacje

Uwierzytelnianie wymagane
Format odpowiedzi json
Metoda HTTP POST

POST webhooks

Ostatnia modyfikacja 2019-11-20 18:04:03
Dodaje element webhook.

URL

https://api.thulium.pl/api/webhooks

Parametry

actions

wymagany

Akcje (zobacz więcej)
subscription_url

wymagany

Docelowy adres URL
http_auth_user

opcjonalny

Login Auth Basic
http_auth_password

opcjonalny

Hasło Auth Basic

Przykładowy request

POST https://api.thulium.pl/api/webhooks
Dane {"actions":["CHAT_CONVERSATION_CREATED"],"subscription_url":"https:\/\/example.pl"}

Przykładowy response

{
        "id": 5,
        "actions": ["CHAT_CONVERSATION_CREATED"],
        "subscription_url": "https://example.pl",
        "http_auth_user": "",
        "http_auth_password": ""
}

Przykładowe wywołanie


PHP

<?php
$data 
'{"actions":["CHAT_CONVERSATION_CREATED"],"subscription_url":"https:\/\/example.pl"}';

$request curl_init('https://api.thulium.pl/api/webhooks');
curl_setopt($requestCURLOPT_HTTPHEADER, array(
    
'Content-Type: application/json; charset=utf-8',
    
'Content-Length: ' mb_strlen($data)
));
curl_setopt($requestCURLOPT_USERPWD'api_user:api_pass');
curl_setopt($requestCURLOPT_TIMEOUT30);
curl_setopt($requestCURLOPT_RETURNTRANSFERtrue);
curl_setopt($requestCURLOPT_CUSTOMREQUEST'POST');
curl_setopt($requestCURLOPT_POSTFIELDS$data);

$response curl_exec($request);
if (
$response) {
    
$httpCode curl_getinfo($requestCURLINFO_HTTP_CODE);
    if (
$httpCode == 200){
        
print_r(json_decode($response));
    } else {
        echo 
$response;
    }
} else {
    
trigger_error(curl_error($request), E_USER_WARNING);
}

curl_close($request);
JAVA

public class Example {
    public static void main(String[] args) throws Exception {
        ThuliumRestClient restClient = new ThuliumRestClient("api_user", "api_pass", true);

        ThuliumRestClient.ThuliumRestResponse response = restClient.post("https://api.thulium.pl/api/webhooks", "{\"actions\":[\"CHAT_CONVERSATION_CREATED\"],\"subscription_url\":\"https:\/\/example.pl\"}");
        System.out.println(response);
    }
}

CURL

curl -u api_user:api_pass -k -X POST -H "Content-type: application/json" -d '{"actions":["CHAT_CONVERSATION_CREATED"],"subscription_url":"https:\/\/example.pl"}' "https://api.thulium.pl/api/webhooks"