3

I want to create a filter from scratch to get just the information I can use:

  • error_id
  • quota_remaining
  • api_site_parameter

The first two are part of the wrapper and the last is part of .items, so I figured this call would work

/2.2/filters/create?include=api_site_parameter;.items;.wrapper&base=none

Unfortunately, this gives

{
  "items": [
    {
      "included_fields": [
        ".items"
      ],
      "filter_type": "safe",
      "filter": "!*YTExG7"
    }
  ],
  "has_more": false,
  "quota_max": 10000,
  "quota_remaining": 9959
}

Using this filter

/2.2/posts?order=desc&sort=activity&site=stackoverflow&filter=!*YTExG7

gives me

{
  "items": []
}

which is exactly what the first response told me I'd get, but is certainly not what I'm trying to achieve. How can I build a filter from scratch?

1 Answer 1

1

I was able to deduce an answer by 'reverse-engineering' (sort of) the default filter:

/2.2/filters/default

this gives

{
  "items": [
    {
      "included_fields": [
        ".backoff",
        ".error_id",
        ".error_message",
        ".error_name",
        ".has_more",
        ".items",
        ".quota_max",
        ".quota_remaining",
        "access_token.access_token",
        "access_token.account_id",
        "access_token.expires_on_date",
        "access_token.scope",
        "account_merge.merge_date",
        ... many lines omitted ...
        "user_timeline.user_id",
        "write_permission.can_add",
        "write_permission.can_delete",
        "write_permission.can_edit",
        "write_permission.max_daily_actions",
        "write_permission.min_seconds_between_actions",
        "write_permission.object_type",
        "write_permission.user_id"
      ],
      "filter_type": "safe",
      "filter": "default"
    }
  ],
  "has_more": false,
  "quota_max": 10000,
  "quota_remaining": 9944
}

It becomes obvious that you must fully specify each field in the method call. The call in the question becomes

/2.2/filters/create?include=site.api_site_parameter;.items&base=none

which, when used with /2.2/sites, gives

{
  "items": [
    { "api_site_parameter": "stackoverflow"     },
    { "api_site_parameter": "serverfault"       },
    { "api_site_parameter": "superuser"         },
    { "api_site_parameter": "meta"              },
    { "api_site_parameter": "webapps"           },
    { "api_site_parameter": "meta.webapps"      },
    { "api_site_parameter": "gaming"            },
    { "api_site_parameter": "meta.gaming"       },
    { "api_site_parameter": "webmasters"        },
    { "api_site_parameter": "meta.webmasters"   },
    { "api_site_parameter": "cooking"           },
    { "api_site_parameter": "meta.cooking"      },
    { "api_site_parameter": "gamedev"           },
    { "api_site_parameter": "meta.gamedev"      },
    { "api_site_parameter": "photo"             },
    { "api_site_parameter": "meta.photo"        },
    { "api_site_parameter": "stats"             },
    { "api_site_parameter": "meta.stats"        },
    { "api_site_parameter": "math"              },
    { "api_site_parameter": "meta.math"         },
    { "api_site_parameter": "diy"               },
    { "api_site_parameter": "meta.diy"          },
    { "api_site_parameter": "meta.superuser"    },
    { "api_site_parameter": "meta.serverfault"  },
    { "api_site_parameter": "gis"               },
    { "api_site_parameter": "meta.gis"          },
    { "api_site_parameter": "tex"               },
    { "api_site_parameter": "meta.tex"          },
    { "api_site_parameter": "askubuntu"         },
    { "api_site_parameter": "meta.askubuntu"    }
  ]
}

You must log in to answer this question.

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