OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • Profile of jkwan »
  • Show Posts »
  • Messages
  • Profile Info
    • Summary
    • Show Stats
    • Show Posts...
      • Messages
      • Topics
      • Attachments

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

  • Messages
  • Topics
  • Attachments

Messages - jkwan

Pages: [1]
1
Development and Code Review / Re: How to user wireguard API (search, add, set)
« on: October 26, 2022, 01:02:28 pm »
Hi,
Thank you for your reply.
I managed to use the APIs except the method for searches

Here is a working CURL example for the addClient method :

Code: [Select]
curl \
--location --request POST 'https://{{fwhost}}/api/wireguard/client/addClient' \
--header 'Authorization: Basic {{token}} \
--header 'Content-Type: application/json' \
--data-raw '{"client":{"tunneladdress":"$address","name":"$user","enabled":1,"pubkey":"$key"}}'

Note that you have to put the client data structure inside a client property.
it's simply a JSON representation of the XML structure described in the documentation :
https://github.com/opnsense/plugins/blob/master/net/wireguard/src/opnsense/mvc/app/models/OPNsense/Wireguard/Client.xml

Same thing for the setClient method, you have just to change the endpoint URL for something like this :
Code: [Select]
https://{{fwhost}}/api/wireguard/client/setClient/{{uuid}}
For the delete method, it seems that empty data have to be posted like this ;
Code: [Select]
curl \
--location --request POST 'https://{{fwhost}}/api/wireguard/client/delClient/{{uuid}}' \
--header 'Authorization: Basic {{token}}' \
--data-raw ''

In my curl examples, {{token}} is base64 encoded of $key:$secret, but you can use -u $key:$secret

Regards,

2
Development and Code Review / How to user wireguard API (search, add, set)
« on: September 19, 2022, 03:06:03 pm »
Hi,

I am struggling with the wireguard API.
https://docs.opnsense.org/development/api/plugins/wireguard.html

Is there an example of how to use the search, set and get endpoints for the client service please ?
I do not understand how to pass the parameter of the search query and the data for add and search endpoint.
An example with curl command will really help me.

edit: I found the way to use all APIs except for search methods

Thanks !

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