Skip to main content

Bonjour la communauté,

Nous souhaitons utiliser le modèle de service HTTP Collection pour interroger une API.

Dans le tuto proposé (https://thewatch.centreon.com/product-how-to-21/http-collections-tutorial-how-to-monitor-an-api-2634), le format du payload utilisé pour la requête POST est json :

"payload": { "type": "json", "value": { "security": { "credentials": { "login": "%(constants.username)", "password": "%(constants.password)" }}}}

L'API que nous souhaitons interroger requiert un content-type "x-www-form-urlencoded".
Exemple de requête généré avec Postman
curl --location 'https://xxx/services/auth/login' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=***' \
--data-urlencode 'password=***'

Nous ne parvenons pas à paramétrer correctement le fichier json de la collection pour prendre en compte ce format d'appel.

Quelqu’un aurait il déjà rencontré (et solutionné 😎 ) ce cas ?

Merci à vous !

Hello,

 

You can format the data as follows:

"payload": {
"type": "data",
"value": "username=%(constants.username)&password=%(constants.password)"
}

 

Here is the HTTP Collections example but for the API v1:

{
"constants": {
"protocol": "https",
"port": "443",
"customPath": "centreon",
"username": "username",
"password": "password"
},
"http": {
"requests": :
{
"name": "authenticationRequest",
"hostname": "%(constants.hostname)",
"proto": "%(constants.protocol)",
"port": "%(constants.port)",
"endpoint": "/%(constants.customPath)/api/index.php?action=authenticate",
"method": "POST",
"headers": :
"Accept:application/json",
"Content-Type:application/x-www-form-urlencoded"
],
"timeout": 30,
"insecure": 1,
"payload": {
"type": "data",
"value": "username=%(constants.username)&password=%(constants.password)"
},
"scenario_stopped": "%(builtin.httpCode.authenticationRequest) != 200",
"backend": "curl",
"rtype": "json",
"parse": :
{
"name": "token",
"path": "$.authToken",
"entries": :
{
"id": "value"
}
]
}
]
}
]
},
"selection": :
{
"name": "authenticationSelection",
"critical": "defined(%(builtin.httpCode.authenticationRequest)) and %(builtin.httpCode.authenticationRequest) != 200",
"formatting": {
"printf_msg": "Authentication resulted in %s HTTP code",
"printf_var": :
"%(builtin.httpCode.authenticationRequest)"
],
"display_ok": true
}
}
]
}

 


Reply