1
General Discussion / Re: API for WOL with Curl
« on: May 22, 2024, 04:10:20 pm »
Hi HansJ
i was stuck at the same error message.
My solution was an python script:
Save it as wol.py for example. Make sure you insert the right interface and MAC.
The python script ist auto generated from here: https://curlconverter.com/python-httpclient/
It will transform the OPNsense API key and secret automaticaly to Base64 for Basic Auth.
My original curl prompt was:
In Windows you have to install python from https://www.python.org/downloads/windows/
When installing add python to system path global vars in Windows.
You can now start your wol.py via cmd or batch script
i was stuck at the same error message.
My solution was an python script:
Code: [Select]
import http.client
import json
import ssl
conn = http.client.HTTPSConnection('$OPNsenseIP:$Port', context=ssl._create_unverified_context())
headers = {
'Content-Type': 'application/json',
'Authorization': 'Basic %Base64 Coded API and Secret Key%',
}
json_data = {
'wake': {
'interface': 'opt1',
'mac': '00:00:00:00:00:00',
},
}
conn.request(
'POST',
'/api/wol/wol/set',
json.dumps(json_data),
# '{"wake":{"interface":"opt1","mac":"00:00:00:00:00:00"}}',
headers
)
response = conn.getresponse()
Save it as wol.py for example. Make sure you insert the right interface and MAC.
The python script ist auto generated from here: https://curlconverter.com/python-httpclient/
It will transform the OPNsense API key and secret automaticaly to Base64 for Basic Auth.
My original curl prompt was:
Code: [Select]
curl -X POST -H 'Content-Type:application/json' -d '{"wake":{"interface":"opt1","mac":"00:00:00:00:00:00"}}' -k -u "$API-Key:$API-Secret" https://$OPNsenseIP:$Port/api/wol/wol/set
In Windows you have to install python from https://www.python.org/downloads/windows/
When installing add python to system path global vars in Windows.
You can now start your wol.py via cmd or batch script
Code: [Select]
@echo off
python C:\pathtopythonscriptfile\wol.py
pause