en général c'est mieux d'attendre que les plugins dont on a besoin soient sortis avant de migrer.
]]>exemple de csv;
jsmith;SMITH;John;JohnsPW;
JNEMAR;NEMAR;Jean;MonMotDePASSE;
pour ce fichier le payload devient
$fields='{"input":
{"name":"'.$TAB[0].'",
"password":"'.sha1($TAB[3]).'",
"realname":"'.$TAB[1].'"
"firstname":"'.$TAB[2].'"
"is_active":1,
"comment":"cree par api",
"profiles_id":1,
"entities_id":1
}
}';
mais vous pouvez avoir un autre csv avec plus de colonnes, il suffit d'u=indiquer dans quelle colonne est l'info
voir ici un truc qui ressemble :
http://forum.glpi-project.org/viewtopic.php?id=157772
Merci de ta réponse
]]>A VALIDER PREALABLEMENT SUR UN SERVEUR DE TESTS.
faites un dump de la base avant import.
activez l'api et les jetons sur GLPI
creez un client localhost
remplacez vos jetons et l'adresse de l'API.
remplacez l'index dans $tab[6] par l'index de colonne correspondante
ne mettez pas de ligne d'entete dans votre csv.
c'ets un petit script rédigé en vitesse , il y a peut être quelques fautes de frappe à corriiger mais dans le principe c'est ça :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- la denree -2017- -->
<head>
<title>TEST API</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="notepad" />
<meta name="Keywords" content="GLPI,import API," />
<meta name="Description" content="imports de users via API REST" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
</head>
<body>
<h1>import users from csv using GLPI API REST</h1>
<?php
echo "<h2>read csv file</h2>";
//initialisation des variables
$mycsvfile="/home/user/Documents/users.csv";
$api_url="http://127.0.0.1/glpi/apirest.php";
$user_token="MYUSERTOKEN";
$app_token ="MyAppToken";
//initialisation api glpi
$ch = curl_init();
$url=$api_url . "/initSession?Content-Type=%20application/json&app_token=".$app_token ."&user_token=".$user_token;
// ligne suivante pour debug à commenter en prod;
echo "<br/>url authentification : " . $url . "<br/>" ;
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
curl_close ($ch);
$obj = json_decode($json,true);
// ligne suivante pour debug à commenter en prod;
print_r($obj);
$sess_token = $obj[session_token];
// ligne suivante pour debug à commenter en prod;
echo " <br/>session token : ". $sess_token ."<br/>";
$headers = array(
('Content-Type: application/json'),
('App-Token: ' . $app_token),
('Session-Token: '.$sess_token)
);
// ligne suivante pour debug à commenter en prod;
print_r($header);
if (!file_exists($mycsvfile)){
die("le fichier n'existe pas");
}
// lecture des lignes du fichier
$ligne=1;
$fic=fopen($mycsvfile, "r");
// on parcoure toutes les lignes du fichier csv;
while($tab=fgetcsv($fic,1024,','))
{
$fields='{
"input": {
"name": "'.$tab[0].'",
"phone": "'.$tab[1].'",
"phone2":"'.$tab[2].'",
"mobile":"'.$tab[3].'",
"realname":"'.$tab[4].'",
"firstname":"'.$tab[5].'",
"use_mode":2,
"list_limit":30,
"is_active":1,
"comment":"'.$tab[6].'",
"is_deleted":0,
"entities_id":2,
"show_jobs_at_login":0,
"set_default_tech":0,
"display_count_on_home":10,
"palette":"purplehaze.min"
}
}';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$request_result = curl_exec($ch);
curl_close ($ch);
$obj = json_decode($request_result,true);
$user_id=$obj['id'];
echo "<br/>$user_id<br/>";
}?>
Merci de vos réponse
]]>