Parameterized API searches?

43 views
Skip to first unread message

Trent Yarosevich

unread,
Feb 28, 2022, 2:52:07 PM2/28/22
to doaj-public-api
Greetings,

I tried making a parameterized get request as I would with a typical REST API using python's requests library, and it seems to build a URL that throws a 404 error. I can certainly call the API with a URL formatted directly to work as shown in the documentation, but this is not my preferred approach as it is less secure. Perhaps I'm doing something wrong, or this approach isn't supported? Here's a simple example:
```
search_string = <search string here>
payload = {
'search_query': search_string,
'page': 0,
'pageSize': 100}

api_return = requests.get(base_url, params=payload)
```

Any insight appreciated, thanks.

best,
Trent Yarosevich
Data Extraction Analyst, IHME, University of Washington

Richard Jones

unread,
Mar 1, 2022, 4:24:00 AM3/1/22
to Trent Yarosevich, doaj-public-api
Hi Trent,

The trick is that the search_query parameter is part of the URL path, not a query argument.  So if you try the following URL you should get a result:


You can play around with this API via the swagger docs on the website, to see how the URLs are built:


Cheers,

Richard


--
You received this message because you are subscribed to the Google Groups "doaj-public-api" group.
To unsubscribe from this group and stop receiving emails from it, send an email to doaj-public-a...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/doaj-public-api/c9ff7c83-356b-4c9b-a04c-56c76cc0fb16n%40googlegroups.com.


--
Richard Jones, 

Steven Eardley

unread,
Mar 1, 2022, 6:49:23 AM3/1/22
to doaj-pu...@googlegroups.com

Hi Trent,

Thanks for pointing this out, it's a little misleading on our documentation page - as Richard points out, the query string is on the URL path rather than a URL parameter. Just minor changes needed to your snippet:

import requests
from urllib.parse import quote, urljoin

base_url = 'https://doaj.org/api/search/articles/'
search_string = quote('title:micro-tensile test')

url_params = {
    'page': 0,
    'pageSize': 100
}

api_return = requests.get(urljoin(base_url, search_string), params=url_params)

print(api_return.request.url)
print(api_return.json().get('results', []))

has the following (truncated) result

https://doaj.org/api/search/articles/title%3Amicro-tensile%20test?page=0&pageSize=100
[{'last_updated': '2021-03-30T23:01:40Z', 'bibjson': {'identifier': [{'id': '10.3390/polym13071093', 'type': 'doi'}, ...

Our API currently works only via path and parameters in the URL - we don't currently support loading those from the request body, since a GET with a payload is a bit anomalous. In any case, HTTPS ensures the path and parameters are encrypted.

Cheers,
Steve

Trent Yarosevich

unread,
Mar 1, 2022, 12:14:42 PM3/1/22
to doaj-public-api
Hi, thanks for the responses, they were very clear. Sounds like the way I was doing it was a bit wonky. Cheers!

best,
Trent

Reply all
Reply to author
Forward
0 new messages