opensanctions/yente

Array query params handling

Opened this issue · 2 comments

Hello,

I would like to discuss the handling of GET query parameters in the OpenSanctions API.

After a thorough debugging, I have identified the reason why my query is not functioning as expected. It is a simple matching request with excluded datasets, as shown below:

Original Query:

https://api.opensanctions.org/match/sanctions?exclude_dataset[]=ua_nabc_sanctions&exclude_dataset[]=ua_nsdc_sanctions&exclude_dataset[]=ua_sfms_blacklist

However, the API expects the following syntax for array parameters:

Expected Query Syntax:

?exclude_dataset=ua_nabc_sanctions&exclude_dataset=ua_nsdc_sanctions&exclude_dataset=ua_sfms_blacklist

In my opinion, this approach seems a bit unconventional. Typically, arrays in GET queries are passed in one of the following common ways:

  1. Using square brackets for each parameter value:
param[]=value1&param[]=value2...
  1. Comma-separated values for a single parameter:
param=value1,value2...

Is this behavior the intended and expected behavior for the OpenSanctions API?

Thank you for your clarification.

pudo commented

Hey! I think there may be a weird programming language idiosyncrasy here: Python likes the straight variant, whereas PHP and Ruby seem to parse the square bracket syntax more easily. Since I'm not super keen on breaking the API, perhaps we could look into defining x[] as an alias for the x variant?

Hi, Friedrich
I believe an alias would be more than enough in this case. However, it would be great to mention such behaviours in the documentation within the parameter description, so users won't be confused by the query syntax.