cambialens / lens-api-doc

10 stars 5 forks source link

passing multiple lens_id in python query #37

Closed shazother closed 3 years ago

shazother commented 3 years ago

trying to pass multiple patent ids in the query using list_id below, not sure how to pass that in the data field

import requests list_id = ["038-537-395-757-496","126-205-264-177-108"]

url = 'https://api.lens.org/patent/search' data = '''{ "query": { "terms": { "lens_id": '''list_id''' } }, "include": ["abstract", "claims","description"] }''' headers = {'Authorization': 'My auth key', 'Content-Type': 'application/json'} response = requests.post(url, data=data, headers=headers) if response.status_code != requests.codes.ok: print(response.status_code) else: pass

shazother commented 3 years ago

figured it out:

import requests import json list_id = ["038-537-395-757-496", "126-205-264-177-108"]

url = 'https://api.lens.org/patent/search' data = '''{ "query": { "terms": { "lens_id": '''+(json.dumps(list_id))+''' } }, "include": ["abstract", "claims","description"] }''' headers = {'Authorization': 'My auth key', 'Content-Type': 'application/json'} response = requests.post(url, data=data, headers=headers) if response.status_code != requests.codes.ok: print(response.status_code) else: pass