Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper format for &search= #6

Closed
voice1 opened this issue Jul 20, 2020 · 1 comment
Closed

Proper format for &search= #6

voice1 opened this issue Jul 20, 2020 · 1 comment

Comments

@voice1
Copy link
Contributor

voice1 commented Jul 20, 2020

The api_extended_search checks to see if the search_data is an array, how are you expecting to pass in an array in the query parameter?

I have tried a few iterations, seach=name[value], both escaped and not, and everything returns
{"status":"not found","code":404,"return":7,"message":"Search attribute not found"}

This sort of makes sense as there is no supported way of passing a PHP array from the CLI, and it does not look like the api_extended_search makes any attempt to convert query strings to a PHP Array.

Is this intended to work?

@jaredhendrickson13
Copy link
Owner

Yes this does work, but not by specifying key value pairs. Look at my examples below to see the proper format for JSON and URL parameters. You must pass in an array of items that can be followed in the API response data. For example, if I make an API call to GET https://localhost/api/v1/system/config/ and specify the search value as ["user", 0, "name"], it will essentially look for the value at $data["user"][0]["name"] with $data being the API response data.

However this is really only useful if you know exactly what you are looking for. I intended this to be a way to pick out specific values from the config file via the API, for example:

Say I wanted to pick a value out of the configuration file that was not available in one of the API endpoints, such as the system optimization value. I know by looking at the XML config this value can be found at system > optimization. I can pull this value from the API like this:

If using URL parameters:

curl -k -X GET 'https://localhost/api/v1/system/config/?client-id=admin&client-token=pfsense&search[]=system&search[]=optimization'

{"status":"ok","code":200,"return":0,"message":"","data":{"optimization":"normal"}}

or if using JSON:

curl -k -d '{"client-id": "admin", "client-token": "pfsense", "search": ["system", "optimization"]}' -X GET https://localhost/api/v1/system/config/

{"status":"ok","code":200,"return":0,"message":"","data":{"optimization":"normal"}}

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants