AAP API: Is the ?fields parameter still valid?

,

I am finding information online that suggests I can limit the field an API call returns by using /?fields=x,y,z on the query. Most of the suggestions I found are in regards to AWX (even the Github AWX repo has this in the Issues section - #508)

When I try this however for jobs, all I get back is “detail”: “Job has no field named ‘fields’”. Am I using it wrong or does this functionality not exists for me?

I have covered a similar topic before: Filter API result by nested field - #8 by Denney-tech

I would treat “fields” as a generic term to refer to the <field_name> that you can filter api queries by with ?. You can usually find what fields are actually filterable by looking under search_fields, related_search_fields, summary_fields or other *_fields.

If you go to the jobs api in your browser, /api/controller/v2/jobs/ (in AAP 2.5 for example), and click on “options”, it will show summary_fields you can filter by and some generic examples. So for example, you could use /api/controller/v2/jobs/?organization_id=1 to get all jobs in the default org. You can filter by nested fields using double underscores such as /api/controller/v2/jobs/?created_by__username=foo_user to find all jobs run by a particular user. Some of the valid fields may happen to be listed in addition to the summary_fields, but not all of them will be valid (such as launched_by).

I’m not asking about filtering the VALUES of the fields, but rather which fields the API call returns. Or did I misunderstand your reply?

I’m telling you can find out what fields are available by simply browsing the api.

OK, yes - I know WHAT fields are available in an API call for FILTERING, I am looking to LIMIT the fields returned from the call. Thanks.

If I understand you correctly, you’re not wanting to filter or limit how many or even which results you get, you want to restrict what keys are returned in the dictionary objects? I don’t think the API has such a feature, you will always get all relevant information/keys for all results that match your query. If you want to remove keys from the list of dict object returned in the API results, you will need to manipulate that json afterwards yourself.

1 Like