-
Notifications
You must be signed in to change notification settings - Fork 7
API Call Examples
-
Sample GET request written in Python with Requests.
-
Note: Presently, get requests only return a HTML response containing endpoint information.
-
Declare the URL.
>>> url ="http://scholarly.io/api/articles"
-
Declare the mimetype and API version in the header.
>>> headers = {"x-api-version": "alpha"}
-
Post the request and capture the response.
>>> response = requests.post(url, headers = headers)
-
Successful posts should return a status code of 200 (success):
>>> print response.status_code >>> 200
-
Unsuccessful posts should return status code of 405 (user submission error):
>>> print response.status_code >>> 405
- Sample POST request written in Python with Requests.
-
Declare the URL.
>>> url = "http://scholarly.io/api/articles/"
-
Declare the mimetype and API version in the header.
>>> headers = {"Content-Type": "application/json", "x-api-version": "alpha"}
-
Set the payload: Note: Scholarly only accepts a json consisting of a primary citation in Citation Style Language (CSL) format (OPTIONALLY) followed by a list of CSL format referenced citations and (OPTIONALLY) provenance information. The CSL schema can be found here: https://github.com/citation-style-language/schema/blob/master/csl-data.json
>>> payload = { "citation": { "id": "item1", "title": "Some article about domokuns.", "author": [ {"given": "tim", "family": "tom" } ], "type": "book" }, "references": [ { "id": "item2", "title": "Some older article about some domokuns.", "author": [ {"given": "chevy", "family": "chaser" } ], "type": "book" }, { "id": "item3", "title": "Some article about some domokun lovers.", "author": [ {"given": "kim", "family": "possibly" } ], "type": "book", "doi": "asdflkj209asdlkfj209sadfkj2" }, { "id": "item4", "title": "Some article about some people who made their fortunes from selling domokuns.", "author": [ {"given": "lyla", "family": "lilly" }, {"given": "jimmy", "family": "jaseper"} ], "type": "webpage", "url": "http://www.pewpew.com/domokun_seller_gets_rich" } ], "metadata": { "source": "some submitter", "parse_style": "manual / parscite / scraping" } }
-
Post the request and capture the response.
>>> response = requests.post(url, data=sample_payload, headers=headers)
-
Successful posts should return a status code of 201 (successfully created):
>>> print response.status_code >>> 201
-
Unsuccessful posts should return status code of 405 (user submission error):
>>> print response.status_code >>> 405
- In progress.
- In progress.