Create user via API on Omada Hotspot Controller

Create user via API on Omada Hotspot Controller

Create user via API on Omada Hotspot Controller
Create user via API on Omada Hotspot Controller
2024-09-30 19:29:11 - last edited 2 weeks ago
Model: OC200  
Hardware Version:
Firmware Version:

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!

  0      
  0      
#1
Options
1 Accepted Solution
Re:Create user via API on Omada Hotspot Controller-Solution
2024-10-01 06:14:14 - last edited 2 weeks ago

Hi  @gb_factory 

 

For Controller v5.11 and above, the Cookie name is “TPOMADA_SESSIONID”.

 

For more details, you may refer to this guide:

API and Code Sample for External Portal Server

Recommended Solution
  0  
  0  
#2
Options
1 Reply
Re:Create user via API on Omada Hotspot Controller-Solution
2024-10-01 06:14:14 - last edited 2 weeks ago

Hi  @gb_factory 

 

For Controller v5.11 and above, the Cookie name is “TPOMADA_SESSIONID”.

 

For more details, you may refer to this guide:

API and Code Sample for External Portal Server

Recommended Solution
  0  
  0  
#2
Options

Information

Helpful: 0

Views: 205

Replies: 1

Related Articles