Comment appeler un Webhook


Comment appeler un Webhook

Ce document décrit la procédure d'appel des Webhooks de Skalin.

Info

Assurez-vous d'avoir obtenu une clé de Webhook au préalable.

# Comment appeler un Webhook

Le code ci-dessous permet l'appel un Webhook :

curl --location \
--request POST 'https://connector.skalin.io/webhook/{{YourWebhookId}}?client_id={{ClientId}}' \
--header 'Cache-Control: no-cache' \
--header 'Content-Type: application/json' \
--data-raw '{
    "eventId":"{{EventId}}",
    "customerId":"{{CustomerId}}",
    "ts":"{{EventTs}}",
    "localtime":"{{LocalTime}}",
    "event": {
        "name": "{{FeatureName}}",
        "score": "{{Score}}"
    }
}'
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Avec NodeJS et la librairie axios (opens new window)

axios({
  method: 'POST',
  url: 'https://connector.skalin.io/webhook/{{YourWebhookId}}',
  headers: {
    'Cache-Control': 'no-cache',
    'Content-Type': 'application/json'
  },
  params: {
    client_id: '{{ClientId}}'
  },
  data: {
    eventId: "{{EventId}}",
    customerId: "{{CustomerId}}",
    ts: "{{EventTs}}"
    localtime: "{{LocalTime}}",
    event: {
        name: "{{FeatureName}}",
        score: {{Score}}
    }
  }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
ClientId

votre identifiant client qui vous a été fourni par Skalin ou est disponible dans la section Paramétrage > Général

EventId Identifiant unique de l'événement de 16 caractères. Permet de gérer la dé-duplication (Le dernier transmit sera conservé).
CustomerId Identifiant du client ou nom de domaine du client
EventTs (facultatif) Timestamp de l'évènement en UTC (`2021-05-08T12:00:05`)
LocalTime (facultatif) heure:minutes:secondes dans la timezone de l'évènement (`08:00:05`)
FeatureName Nom de la fonctionnalité utilisée
Score Score associé à l'évènement.
- 1 : Très mauvais (minimum)
- 5 : Très bon (maximum)

Info

CustomerId correspond à la propriété refId de l'API (champ Customer ID de l'interface d'édition du client)

Javascript

axios({
  method: 'POST',
  url: 'https://connector.skalin.io/webhook/05cb3204b49ff92d',
  headers: {
    'Cache-Control': 'no-cache',
    'Content-Type': 'application/json'
  },
  params: {
    client_id: '2bb91c92dr779103'
  },
  data: {
    eventId: "e07595f29f1928y5",
    customerId: "customer1234",
    event: {
        name: "ActivationService",
        score: 5
    }
  }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Ceci est un exemple d'appel lors de l'activation d'un service fictif d'une plaforme et qui représente un évènement positif pour l'usage du client.


Shell script

curl --location \
--request POST 'https://connector.skalin.io/webhook/05cb3204b49ff92d?client_id=2bb91c92dr779103' \
--header 'Cache-Control: no-cache' \
--header 'Content-type: application/json' \
--data-raw '{
    "eventId":"e07595f29f1928y5",
    "customerId":"customer1234",
    "event": {
        "name": "ActivationService",
        "score": 5
    }
}'
1
2
3
4
5
6
7
8
9
10
11
12

Python

import requests
import json

url = 'https://connector.skalin.io/webhook/05cb3204b49ff92d'

headers = {'Content-Type': 'application/json', 'Cache-Control': 'no-cache'}

params = {"client_id": "2bb91c92dr779103"}

data = {
    "eventId": "e07595f29f1928y5",
    "customerId": "customer1234",
    "event": {
        "name": "ActivationService",
        "score": 5
    }
}

response = requests.post(url=url, headers=headers, params=params, data=json.dumps(data))

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Php

// Your ClientId and webhookId
$clientId = '2bb91c92dr779103';
$webhooId = '05cb3204b49ff92d';

$featureName = 'ActivationService';
$featureScore = 5;

$url = 'https://connector.skalin.io/webhook/'.$webhooId.'?client_id='.$clientId;

// The data to send to the API
$postData = array(
    'eventId' => 'e07595f29f1928y5',
    'customerId' => 'customer1234',
    'event' => array('name' => $featureName, 'score' => $featureScore)
);

// Create the context for the request
$context = stream_context_create(array(
    'http' => array(
        'method' => 'POST',
        'header' => "Cache-Control: no-cache\r\n".
            "Content-Type: application/json\r\n",
        'content' => json_encode($postData)
    )
));

// Send the request
$response = file_get_contents($url, FALSE, $context);

// Check for errors
if($response === FALSE){
    die('Error');
}

// Decode the response
$responseData = json_decode($response, TRUE);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Contributeurs: Julien