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 :
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 :
For the delete method, it seems that empty data have to be posted like this ;
In my curl examples, {{token}} is base64 encoded of $key:$secret, but you can use -u $key:$secret
Regards,
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,