Omada V2 API

This thread has been locked for further replies. You can start a new thread to share your ideas or ask questions.

Omada V2 API

This thread has been locked for further replies. You can start a new thread to share your ideas or ask questions.
50 Reply
Re:Omada V2 API-Solution
2022-02-14 13:35:52 - last edited 2023-12-12 08:49:07

  @straydog 

 

Here is an example that I have validated to work on version 5.0.30: https://gist.github.com/mbentley/03c198077c81d52cb029b825e9a6dc18

 

Also copied here for completeness:

 

# set variables
OMADA_URL="https://omada.example.com:8443"
USERNAME="admin"
PASSWORD="test12345"

# get controller id from the API
CONTROLLER_ID="$(curl -sk "${OMADA_URL}/api/info" | jq -r .result.omadacId)"

# login, get token, set & use cookies
TOKEN="$(curl -sk -X POST -c "/tmp/omada-cookies.txt" -b "/tmp/omada-cookies.txt" -H "Content-Type: application/json" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/login" -d '{"username": "'"${USERNAME}"'", "password": "'"${PASSWORD}"'"}' | jq -r .result.token)"

# once logged in, make sure you add the following header on additional API calls:
# -H "Csrf-Token: ${TOKEN}"

# validate login
curl -sk -X GET -b "/tmp/omada-cookies.txt" -H "Content-Type: application/json" -H "Csrf-Token: ${TOKEN}" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/loginStatus?token=${TOKEN}" | jq .

# example to get info on the current user
curl -sk -X GET -b "/tmp/omada-cookies.txt" -H "Content-Type: application/json" -H "Csrf-Token: ${TOKEN}" "${OMADA_URL}/${CONTROLLER_ID}/api/v2/users/current?token=${TOKEN}&currentPage=1&currentPageSize=1000"
Recommended Solution
  12  
  12  
#33
Options
Re:Omada V2 API
2022-02-14 22:13:19 - last edited 2022-12-29 08:36:07
Thank you, that helped a lot to get it working ;)
  0  
  0  
#34
Options
Re:Omada V2 API
2022-02-15 02:31:40 - last edited 2022-12-29 08:36:07

  @mbentley 

Unrelated, but thank you for all your work keeping the docker containers up to date. My homelab thanks you as well 

  2  
  2  
#35
Options
Re:Omada V2 API
2022-03-19 01:51:17 - last edited 2022-12-29 08:36:07
i'd like to see your code plz, i am strugling to get the crsf_token
  0  
  0  
#36
Options
Re:Omada V2 API
2022-03-19 01:53:15 - last edited 2022-12-29 08:36:07

  @Enigma22 It's all there in my post. Not sure what else you might need.

  0  
  0  
#37
Options
Re:Omada V2 API
2022-03-19 02:22:33 - last edited 2022-12-29 08:36:07

  @mbentley I'am still not able to get the token, i am using php curl, i tryed a lot of port, 8088, 8043, 433, 443, 8843, and in everytime the answer is the same : connection timedout

  0  
  0  
#38
Options
Re:Omada V2 API
2022-03-31 02:58:03 - last edited 2022-12-29 08:36:07

@mbentley 

Also wanted to echo my thanks for your Docker image of the Controller...now running on my (old) Synology NAS ~550MB footprint!  Much better than I managed!

<< Paying it forward, one juicy problem at a time... >>
  0  
  0  
#39
Options
Re:Omada V2 API
2022-04-14 20:35:14 - last edited 2022-12-29 08:36:07
@mbentley Thankx a lot for your scipts about the api, they where a big basic help for understanding the api better! And your docker container is great! Good work!
  0  
  0  
#40
Options
Re:Omada V2 API
2022-06-30 18:53:57 - last edited 2022-12-29 08:36:07

We successfully used the Omada APIs V2 to integrate Omada with Cusna.io

 

Cusna helps to deliver easy and securt managed WiFi in MDU scenario. We use the APIs to manage automatically the PPSK lifecycle, assigning to each resident an individual PPSK on a dedicated VLAN in order to have them connected to all their home smart devices.

The operator only has to activate the resident without worrying at all about the IT configuration.

Residents, via their portal, can also change the PPSK at any time for increase security, in case the susbpect someone guess their PSK and entered in their network.

 

https://cusna.io

 

Looking forward to havign your feedbacks!

  0  
  0  
#41
Options
Re:Omada V2 API
2022-07-12 21:20:55 - last edited 2022-12-29 08:36:07

  @mbentley @fae I have tried to reproduce a simple API usage with node but I don't get beyond the login. I am able to login and get the token but then all subsequent requests just get an empty webpage as body result, no API response. Any idea what's going on?

I am unclear if the cookies are needed, I would not expect this for a REST API.

 

Example of the login:

var form = {

"username": "",

"password": ""

};

var formData = JSON.stringify(form);

request({

headers: {

'Content-Type': 'application/json'

},

uri: OMADA_URL+OMADA_CONTROLLER+'/api/v2/login',

body: formData,

method: 'POST'

}, function (err, res, body) {

if (err) {

log(err);

} else {

token = JSON.parse(body).result.token;

}

});

 

Example of a failed request:

request({

headers: {

'Csrf-Token': token,

'Content-Type': 'application/json'

},

uri: OMADA_URL+OMADA_CONTROLLER+'/api/v2/sites/Default/clients/'+mac,

method: 'GET'

}, function (err, res, body) {

if (err) {

log(err);

} else {

log(body);

}

});

  0  
  0  
#42
Options