OPNsense Forum

English Forums => General Discussion => Topic started by: verfluchten on November 16, 2024, 10:41:05 PM

Title: Am I using the API wrong?
Post by: verfluchten on November 16, 2024, 10:41:05 PM
I registered a user for API access, plugged its key and secret into curl, and got nowhere:

$ curl -k "https://xx.xx.xx.xx/api/core/backup/providers/?key=ABC&secret=XYZ"
{"message":"controller OPNsense\\Core\\Api\\BackupController not found","status":400}$
$ curl -k "https://xx.xx.xx.xx/api/core/firmware/status?key=ABC&secret=XYZ"
$
Title: Re: Am I using the API wrong?
Post by: peskytech on November 21, 2024, 03:44:20 PM
You may want to change your format, you are getting a 400 error, so your request is incorrect:
    curl  -k -u user:secret  https://X.X.X.X/api/core/backup/providers
Response:
    {"items":{"this":{"description":"This Firewall","dirname":"\/conf\/backup"}}}

The HTTP 400 Bad Request client error response status code indicates that the server would not process the request due to something the server considered to be a client error.
Title: Re: Am I using the API wrong?
Post by: verfluchten on November 21, 2024, 05:12:15 PM
Quote from: peskytech on November 21, 2024, 03:44:20 PM
You may want to change your format, you are getting a 400 error, so your request is incorrect:
    curl  -k -u user:secret  https://X.X.X.X/api/core/backup/providers
Response:
    {"items":{"this":{"description":"This Firewall","dirname":"\/conf\/backup"}}}

The HTTP 400 Bad Request client error response status code indicates that the server would not process the request due to something the server considered to be a client error.

With your command format, I still get the same error 400 controller not found. Nothing changed.
Title: Re: Am I using the API wrong?
Post by: Monviech (Cedrik) on November 21, 2024, 05:27:03 PM
Try this endpoint to download the latest configuration:

https://xxx.xxx.xxx.xxx/api/core/backup/download/this

https://github.com/opnsense/core/commit/39b531783
Title: Re: Am I using the API wrong?
Post by: verfluchten on November 21, 2024, 06:38:31 PM
Quote from: Monviech (Cedrik) on November 21, 2024, 05:27:03 PM
Try this endpoint to download the latest configuration:

https://xxx.xxx.xxx.xxx/api/core/backup/download/this

https://github.com/opnsense/core/commit/39b531783

Is that available in a specific version? Which one?
Title: Re: Am I using the API wrong?
Post by: Monviech (Cedrik) on November 21, 2024, 06:46:38 PM
I tried with 24.7.8 but it should be around for a while.
Title: Re: Am I using the API wrong?
Post by: verfluchten on November 22, 2024, 01:39:19 AM
Quote from: Monviech (Cedrik) on November 21, 2024, 06:46:38 PM
I tried with 24.7.8 but it should be around for a while.

Does the API work at all in 21.7.8? Upgrading is not an option.
Title: Re: Am I using the API wrong?
Post by: Monviech (Cedrik) on November 22, 2024, 06:46:50 AM
You probably need the os-api-backup plugin on older versions, if it exists in yours.

https://forum.opnsense.org/index.php?topic=18218.0
Title: Re: Am I using the API wrong?
Post by: verfluchten on November 22, 2024, 01:05:51 PM
Quote from: Monviech (Cedrik) on November 22, 2024, 06:46:50 AM
You probably need the os-api-backup plugin on older versions, if it exists in yours.

https://forum.opnsense.org/index.php?topic=18218.0

That was the first thing that I've done before trying to use the API.