Points de terminaison Ping
Surveillance de la santé et test de connectivité pour l'API Actions.
Aperçu
Les points de terminaison ping fournissent un moyen simple de tester la connectivité et de valider l'authentification avec mindzieAPI. Ces points de terminaison sont essentiels pour surveiller la santé du système et résoudre les problèmes de connexion.
Ping non authentifié
GET /api/{tenantId}/{projectId}/action/unauthorized-ping
Test de connectivité basique qui ne nécessite pas d’authentification. Utilisez ceci pour vérifier que l’API est accessible.
Requête
GET https://your-mindzie-instance.com/api/{tenantId}/{projectId}/action/unauthorized-ping
Paramètres de chemin
| Paramètre | Type | Obligatoire | Description |
|---|---|---|---|
tenantId |
GUID | Oui | Votre identifiant de locataire |
projectId |
GUID | Oui | Votre identifiant de projet |
Réponse
HTTP/1.1 200 OK
Content-Type: text/plain
Ping Successful
Cas d'utilisation
- Test basique de connectivité
- Contrôles de santé des équilibreurs de charge
- Résolution de problèmes réseau
- Surveillance de la disponibilité du service
Ping authentifié
GET /api/{tenantId}/{projectId}/action/ping
Test de connectivité authentifié qui valide les identifiants et vérifie l'accès au locataire et au projet spécifiés.
Requête
GET https://your-mindzie-instance.com/api/{tenantId}/{projectId}/action/ping
Authorization: Bearer {your-access-token}
Paramètres de chemin
| Paramètre | Type | Obligatoire | Description |
|---|---|---|---|
tenantId |
GUID | Oui | Votre identifiant de locataire |
projectId |
GUID | Oui | Votre identifiant de projet |
Réponse
Succès (200 OK):
HTTP/1.1 200 OK
Content-Type: text/plain
Ping Successful (tenant id: 12345678-1234-1234-1234-123456789012)
Non autorisé (401):
HTTP/1.1 401 Unauthorized
Content-Type: text/plain
{error message describing authorization failure}
Cas d'utilisation
- Validation d’authentification
- Vérification des permissions
- Test de validité du token
- Validation d’accès au locataire/projet
Exemples d'implémentation
cURL
# Ping non authentifié
curl -X GET "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/87654321-4321-4321-4321-210987654321/action/unauthorized-ping"
# Ping authentifié
curl -X GET "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/87654321-4321-4321-4321-210987654321/action/ping" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
JavaScript/Node.js
const TENANT_ID = '12345678-1234-1234-1234-123456789012';
const PROJECT_ID = '87654321-4321-4321-4321-210987654321';
const BASE_URL = 'https://your-mindzie-instance.com';
// Ping non authentifié
const unauthorizedPing = async () => {
const response = await fetch(
`${BASE_URL}/api/${TENANT_ID}/${PROJECT_ID}/action/unauthorized-ping`
);
const text = await response.text();
console.log('Ping non authentifié :', text);
return response.ok;
};
// Ping authentifié
const authenticatedPing = async (token) => {
const response = await fetch(
`${BASE_URL}/api/${TENANT_ID}/${PROJECT_ID}/action/ping`,
{
headers: {
'Authorization': `Bearer ${token}`
}
}
);
if (response.ok) {
const text = await response.text();
console.log('Ping authentifié :', text);
return true;
} else {
console.error('Échec de l’authentification :', response.status);
return false;
}
};
Python
import requests
TENANT_ID = '12345678-1234-1234-1234-123456789012'
PROJECT_ID = '87654321-4321-4321-4321-210987654321'
BASE_URL = 'https://your-mindzie-instance.com'
def unauthorized_ping():
"""Test basique de connectivité sans authentification."""
url = f'{BASE_URL}/api/{TENANT_ID}/{PROJECT_ID}/action/unauthorized-ping'
response = requests.get(url)
print(f'Ping non authentifié : {response.text}')
return response.ok
def authenticated_ping(token):
"""Test de connectivité authentifié."""
url = f'{BASE_URL}/api/{TENANT_ID}/{PROJECT_ID}/action/ping'
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.get(url, headers=headers)
if response.ok:
print(f'Ping authentifié : {response.text}')
return True
else:
print(f'Échec de l’authentification : {response.status_code}')
return False
C#
using System.Net.Http;
using System.Threading.Tasks;
public class ActionApiClient
{
private readonly HttpClient _httpClient;
private readonly string _baseUrl;
private readonly Guid _tenantId;
private readonly Guid _projectId;
public ActionApiClient(string baseUrl, Guid tenantId, Guid projectId, string accessToken)
{
_baseUrl = baseUrl;
_tenantId = tenantId;
_projectId = projectId;
_httpClient = new HttpClient();
_httpClient.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
}
public async Task<bool> UnauthorizedPingAsync()
{
var url = $"{_baseUrl}/api/{_tenantId}/{_projectId}/action/unauthorized-ping";
var response = await _httpClient.GetAsync(url);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Ping non authentifié : {content}");
return response.IsSuccessStatusCode;
}
public async Task<bool> AuthenticatedPingAsync()
{
var url = $"{_baseUrl}/api/{_tenantId}/{_projectId}/action/ping";
var response = await _httpClient.GetAsync(url);
var content = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Ping authentifié : {content}");
return true;
}
else
{
Console.WriteLine($"Échec de l’authentification : {response.StatusCode}");
return false;
}
}
}
Bonnes pratiques
- Contrôles de santé : Utilisez le ping non authentifié pour les systèmes automatisés de surveillance de la santé
- Validation préalable : Appelez le ping authentifié avant d’exécuter des actions pour valider les identifiants
- Gestion des erreurs : Gérez toujours de manière élégante les délais d’attente réseau et les échecs d’authentification
- Surveillance : Configurez des alertes automatisées basées sur les échecs de ping pour détecter tôt les interruptions de service