4

I used the following request link to extract data from the Stack Exchange API. But I have no idea how to create "filter" as used in the request line.

Please help me understand the creation of such filter in order to get the desired fields in response the response.

https://api.stackexchange.com/2.1/users/2/answers?key=xTr7YgsHdmfcevW6Vo1*BQ((&page=1&pagesize=100&site=stackoverflow&filter=!3u0zcO%28lpHVEGuskA

1

1 Answer 1

8

You can create and edit filters from the documentation page of the API endpoint.

So you start at the Index of all endpoints. There you'll find /users/{id}/answers.

On the right at the top of the parameter block you'll find the filter dialog:

filter dialog button

When you click the [edit] link the filter dialog opens:

filter dialog

Where you can expand any the [types] provided by this endpoint.

edit fields

If you click [Save] you'l get a magic number representing your selection.

You can also provide an that magic when you start editing. You take the filter value from the url, in your case:

!3u0zcO%28lpHVEGuskA

but notice it has %28 in it which indicate it is URL encoded. So we first reverse that by running this in the Developer Tools Console of your browser (On Windows based browsers the Console can often be started by pressing the key F12, at least on the most popular browsers, like Chrome)

decodeURI('!3u0zcO%28lpHVEGuskA');

which returns

!3u0zcO(lpHVEGuskA

You can copy-paste that value in the textbox at the top of the filter dialog, to get the types and fields that were selected for that magic number:

update fields

Another option is to use the read-filter endpoint which returns an object showing the selected fields for a particular filter.

2
  • What do you mean with "Developer Console"?
    – Erfan
    Commented Aug 10, 2020 at 0:07
  • @Erfan The Dev console in the browser. I added an explanation and link to the docs of two of the browsers.
    – rene
    Commented Aug 10, 2020 at 6:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .