230 lines
7.8 KiB
PHP
230 lines
7.8 KiB
PHP
<?php
|
|
//print_r(jira_recherche_email("stephan@va-voir.com"));
|
|
|
|
// create
|
|
$data['serviceDeskId'] = 2; // Remplacez par l'ID réel de votre Service Desk
|
|
$data['requestTypeId'] = 4; // Remplacez par l'ID réel du type de demande
|
|
$data['summary']=utf8_encode('Problème avec le service');
|
|
$data['description']=utf8_encode('Détails du problème rencontré.');
|
|
$data['typedemande']=utf8_encode('Demande soummision');
|
|
$data['raiseOnBehalfOf']= "stephan@va-voir.com" ;
|
|
|
|
print_r(jira_create_ticket($data));
|
|
//print_r(jira_creer_user("test2@va-voir.com","test"));
|
|
function jira_recherche_email($param)
|
|
{
|
|
// recherche user
|
|
$jiraDomain = 'https://progiwebinc.atlassian.net'; // Remplacez par le domaine de votre Jira
|
|
// API que vous voulez appeler
|
|
$admin_email = 'stephan@progiweb.ca'; // Remplacez par votre email
|
|
$api_token = 'ATATT3xFfGF0DuhOhRUxFlj2hFpLuzYGapJIrhMETB35NnLFi1TyxDszp3tTa8MaadTpT72GfDk9FOpDm07m6HbdXoQ9plDeRvB6OwRnD19VrIqA8M3HmDGgf_MWR7Pwk5731ahbgb4UBdRgj-ICBqt9A0SjJPnnoTfu4ECVh51HjM0RsekOmeM=908B030C'; // Remplacez par votre jeton d'API
|
|
$apiEndpoint = '/rest/api/3/user/search?query=email@example.com';
|
|
|
|
// URL de votre instance Jira
|
|
|
|
|
|
// Email à rechercher
|
|
$email = $param;
|
|
|
|
|
|
|
|
// Initialiser cURL
|
|
$ch = curl_init();
|
|
|
|
// Point de terminaison pour rechercher un utilisateur
|
|
$url = $jiraDomain . '/rest/api/3/user/search?query=' . urlencode($email);
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
'Authorization: Basic ' . base64_encode($admin_email . ':' . $api_token),
|
|
'Content-Type: application/json',
|
|
]);
|
|
|
|
// Exécuter la requête et obtenir la réponse
|
|
$response = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
// Décoder la réponse JSON
|
|
$result = json_decode($response, true);
|
|
$sortie=array();
|
|
$sortie['statut']=0;
|
|
// Filtrer pour une correspondance exacte sur l'email
|
|
$exact_match = null;
|
|
if (!empty($result)) {
|
|
|
|
foreach ($result as $user) {
|
|
if (isset($user['emailAddress']) && strtolower($user['emailAddress']) === strtolower($email)) {
|
|
$sortie['statut']=1;
|
|
$sortie['jira']=$user;
|
|
$exact_match = $user;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $sortie ;
|
|
}
|
|
function jira_creer_user($email,$displayName)
|
|
{
|
|
|
|
|
|
$jiraDomain = 'https://progiwebinc.atlassian.net'; // Remplacez par le domaine de votre Jira
|
|
// API que vous voulez appeler
|
|
$userEmail = 'stephan@progiweb.ca'; // Remplacez par votre email
|
|
$apiToken = 'ATATT3xFfGF0DuhOhRUxFlj2hFpLuzYGapJIrhMETB35NnLFi1TyxDszp3tTa8MaadTpT72GfDk9FOpDm07m6HbdXoQ9plDeRvB6OwRnD19VrIqA8M3HmDGgf_MWR7Pwk5731ahbgb4UBdRgj-ICBqt9A0SjJPnnoTfu4ECVh51HjM0RsekOmeM=908B030C'; // Remplacez par votre jeton d'API
|
|
$apiEndpoint = '/rest/servicedeskapi/customer';
|
|
|
|
|
|
|
|
|
|
// Encodage de l'authentification en Base64
|
|
$authHeader = base64_encode("$userEmail:$apiToken");
|
|
|
|
// Corps de la requête
|
|
$postData = json_encode([
|
|
'email' => $email,
|
|
'displayName' => $displayName
|
|
]);
|
|
|
|
// Initialisation de cURL
|
|
$ch = curl_init("$jiraDomain$apiEndpoint");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
"Authorization: Basic $authHeader",
|
|
"Content-Type: application/json",
|
|
"Accept: application/json"
|
|
]);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
|
|
|
// Exécuter la requête
|
|
$response = curl_exec($ch);
|
|
$result = json_decode($response, true);
|
|
$sortie=array();
|
|
$sortie['statut']=0;
|
|
// Gérer les erreurs
|
|
if (curl_errno($ch)) {
|
|
// echo 'Erreur cURL : ' . curl_error($ch);
|
|
$sortie['statut']=curl_error($ch);
|
|
} else {
|
|
// Vérifier le code HTTP pour voir si le client existe déjà
|
|
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
if ($httpcode == 201) {
|
|
// echo "Le client a été créé avec succès.";
|
|
$sortie['success']=1;
|
|
$sortie['statut']= $result;
|
|
} elseif ($httpcode == 400) {
|
|
// Traiter le cas où l'email existe déjà
|
|
$responseData = json_decode($response, true);
|
|
|
|
$sortie['success']=2;
|
|
if (isset($responseData['errors']) && strpos($responseData['errors'][0]['message'], 'already exists') !== false) {
|
|
// echo "Le client avec cet email existe déjà.";
|
|
$sortie['success']=2;
|
|
$sortie['statut']= $result;
|
|
} else {
|
|
//echo "Une erreur s'est produite : " . $response;
|
|
$sortie['statut']= $result;
|
|
$sortie['success']=2;
|
|
}
|
|
} else {
|
|
$sortie['success']=0;
|
|
// echo "Erreur inattendue : " . $response;
|
|
$sortie['statut']= $result;
|
|
}
|
|
}
|
|
|
|
// Fermer la session cURL
|
|
curl_close($ch);
|
|
return($sortie);
|
|
}
|
|
|
|
function jira_create_ticket( $param)
|
|
{
|
|
|
|
// Domaine Jira
|
|
$jiraDomain = 'https://progiwebinc.atlassian.net'; // Remplacez par le domaine de votre Jira
|
|
|
|
// Informations d'authentification
|
|
$userEmail = 'stephan@progiweb.ca'; // Remplacez par votre email
|
|
$apiToken = 'ATATT3xFfGF0DuhOhRUxFlj2hFpLuzYGapJIrhMETB35NnLFi1TyxDszp3tTa8MaadTpT72GfDk9FOpDm07m6HbdXoQ9plDeRvB6OwRnD19VrIqA8M3HmDGgf_MWR7Pwk5731ahbgb4UBdRgj-ICBqt9A0SjJPnnoTfu4ECVh51HjM0RsekOmeM=908B030C'; // Remplacez par votre jeton d'API
|
|
|
|
|
|
|
|
// Les informations du ticket
|
|
$data = [
|
|
'serviceDeskId' => $param['serviceDeskId'],
|
|
'requestTypeId' => $param['requestTypeId'],
|
|
|
|
'requestFieldValues' => [
|
|
'summary' => $param['summary'],
|
|
'description' => $param['description'],
|
|
'customfield_11143' => $param['typedemande'],
|
|
],
|
|
'raiseOnBehalfOf' => $param['raiseOnBehalfOf'], // Remplacez par l'accountId du client (facultatif)
|
|
] ;
|
|
|
|
$jsonData = json_encode($data);
|
|
|
|
// if ($jsonData === false) {
|
|
// echo "Erreur dans l'encodage JSON : " . json_last_error_msg();
|
|
// } else {
|
|
// echo $jsonData; // Afficher les données encodées
|
|
// }
|
|
|
|
|
|
// Initialiser cURL
|
|
$ch = curl_init();
|
|
|
|
// Point de terminaison pour créer une demande
|
|
$url = $jiraDomain . '/rest/servicedeskapi/request';
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
'Authorization: Basic ' . base64_encode($userEmail . ':' . $apiToken),
|
|
'Content-Type: application/json; charset=UTF-8',
|
|
]);
|
|
|
|
// Exécuter la requête et obtenir la réponse
|
|
$response = curl_exec($ch);
|
|
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
$sortie['success']=0;
|
|
|
|
$sortie['statut']="";
|
|
// Vérifier si le contenu de la réponse est vide
|
|
if ($response === false || empty($response)) {
|
|
// Gérer les réponses vides ou erreurs
|
|
if ($httpcode == 204) {
|
|
$sortie['success']=1;
|
|
$sortie['statut']="Le ticket a été créé avec succès, mais la réponse est vide (204 No Content).";
|
|
|
|
} else {
|
|
$sortie['success']=0;
|
|
$sortie['statut']="Erreur : Le serveur a renvoyé une réponse vide. Code HTTP : " . $httpcode;
|
|
|
|
}
|
|
} else {
|
|
// Décoder la réponse JSON seulement si elle n'est pas vide
|
|
$decoded_response = json_decode($response, true);
|
|
|
|
if ($httpcode == 201) {
|
|
$sortie['success']=1;
|
|
$sortie['statut']= $decoded_response;
|
|
|
|
} else {
|
|
$sortie['success']=0;
|
|
$sortie['statut']= $response;
|
|
|
|
}
|
|
}
|
|
|
|
return( $sortie);
|
|
}
|
|
|
|
//ATATT3xFfGF0DuhOhRUxFlj2hFpLuzYGapJIrhMETB35NnLFi1TyxDszp3tTa8MaadTpT72GfDk9FOpDm07m6HbdXoQ9plDeRvB6OwRnD19VrIqA8M3HmDGgf_MWR7Pwk5731ahbgb4UBdRgj-ICBqt9A0SjJPnnoTfu4ECVh51HjM0RsekOmeM=908B030C
|