OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • English Forums »
  • Development and Code Review (Moderator: fabian) »
  • Understanding API docs
« previous next »
  • Print
Pages: [1]

Author Topic: Understanding API docs  (Read 4156 times)

bubbagump

  • Newbie
  • *
  • Posts: 39
  • Karma: 5
    • View Profile
Understanding API docs
« on: March 19, 2021, 01:39:34 pm »
I want to automate a few items to toggle routes and and other simple things via the API. The first item I am trying to do is toggle enable/disable an alias. (Toggle alias on, a certain host in the alias matches a conditional route and routes out gateway B. Toggle off, it routes out gateway A.)

I have a user and API access is working. For instance, I ran

Code: [Select]
curl -k -u "sometoken":"somekey" https://192.168.40.2/api/firewall/alias/getAliasUUID/SomeAliasand voila I got back

{"uuid":"44724741-c37e-419a-9fa2-3aad79111335"}

Fantastic. Auth works.

Now I am completely lost on making the POST. I tried this based on the POST example here https://docs.opnsense.org/development/how-tos/api.html.

Code: [Select]
curl -XPOST -d '{"ed8a5bf8-861a-4307-a7b4-df1b2a727d18":"null"}' -H "Content-Type: application/json" -k -u "sometoken":"somekey" https://192.168.40.2/api/firewall/alias/toggleItem

and I get

Code: [Select]
{"message":"action toggleItem expects at least 1 parameter(s)","status":400}
which I half expect as I have no clue what values to put in. The docs say Parameter $uuid,$enabled=null. Great, I have a uuid, what values are allowed for $enabled? I have tried true/false, 1/0. Is there a table somewhere that describes these values? Or am I so green there is some convention here that a real dev would understand that I don't? Thanks!
Logged

mimugmail

  • Hero Member
  • *****
  • Posts: 6767
  • Karma: 494
    • View Profile
Re: Understanding API docs
« Reply #1 on: March 19, 2021, 02:19:41 pm »
I didn't work with Alias yet, but I'd suggest you type F12 in browser and do this by hand, then you'll see the API calls sent via browser
Logged
WWW: www.routerperformance.net
Support plans: https://www.max-it.de/en/it-services/opnsense/
Commercial Plugins (German): https://opnsense.max-it.de/

bubbagump

  • Newbie
  • *
  • Posts: 39
  • Karma: 5
    • View Profile
Re: Understanding API docs
« Reply #2 on: March 19, 2021, 03:57:43 pm »
Ooooo, that's clever. Thank you!
Logged

bubbagump

  • Newbie
  • *
  • Posts: 39
  • Karma: 5
    • View Profile
Re: Understanding API docs
« Reply #3 on: March 19, 2021, 04:19:24 pm »
Here we go...

Code: [Select]
curl -k -u "sometoken":"somekey" 'https://192.168.40.2/api/firewall/alias/toggleItem/44724741-c37e-419a-9fa2-3aad79111335'  --data-raw '{}'
"$enabled=null" in the docs simply mean to pass a null set in the --data-raw - so hopefully this helps someone somewhere.

Logged

mimugmail

  • Hero Member
  • *****
  • Posts: 6767
  • Karma: 494
    • View Profile
Re: Understanding API docs
« Reply #4 on: March 19, 2021, 06:00:13 pm »
Thx for sharing
Logged
WWW: www.routerperformance.net
Support plans: https://www.max-it.de/en/it-services/opnsense/
Commercial Plugins (German): https://opnsense.max-it.de/

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • English Forums »
  • Development and Code Review (Moderator: fabian) »
  • Understanding API docs
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2024 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2