Create user via API on Omada Hotspot Controller
Hello, I'm trying to create users on Omada Hotspot Controller via PHP API.
This is the code used to log in:
$url = "https://IP:PORT/CONTROLLERID/api/v2/hotspot/login";
$content = json_encode(array(
'name' => 'USERNAME',
'password' => 'PASSWORD',
));
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$curl,
CURLOPT_HTTPHEADER,
array("Content-type: application/json")
);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
curl_close($curl);
$response = json_decode($json_response, true);
Then, when I get the token, I use the following code to create the user:
$url = "https://IP:PORT/CONTROLLERID/api/v2/hotspot/sites/SITEID/localusers";
$content = json_encode(array(
"id" => null,
"userName" => $username,
"password" => $password,
"enable" => true,
"logout" => true,
"expirationTime" => 1756681199999,
"bindingType" => 0,
"maxUsers" => 1,
"name" => "",
"phone" => null,
"rateLimitId" => "RATELIMITID",
"trafficLimitEnable" => false,
"trafficLimit" => null,
"portals" => array(
"PORTALID"
)
));
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Csrf-Token: ' . $token
]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$curl,
CURLOPT_HTTPHEADER,
array("Content-type: application/json")
);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
curl_close($curl);
$response = json_decode($json_response, true);
The token gets created, but I can't create the user, nothing comes back grom the response.
On my PC i tryed the endpoints with Postman and everything works, I think the problem is with cookies, has someone accomplished something similar and can help me out?
Thanks!