This my first time hooking up to an API. I'm attempting to query NIH project data and can seem to hook up correctly to it as I get a status code of 200. The issue I have is when I try to print the output. I get a URL rejection despite having access. The documentation suggests that if any issues come up, it may be due to my IP being blocked due to a variety of reasons. I reached out to the API support team there and I don't have any issues with a blocked IP. They had me run some curl
requests via command prompt and I was able to execute those correctly. This leads me to believe I have a code issue. What am I doing wrong here?
import requests
params = {
"criteria":
{
"fiscal_years":[2019,2018]
},
"include_fields": [
"ApplId","SubprojectId","FiscalYear","Organization", "ProjectNum","OrgCountry",
"ProjectNumSplit","ContactPiName","AllText","FullStudySection",
"ProjectStartDate","ProjectEndDate"
],
"offset":0,
"limit":25,
"sort_field":"project_start_date",
"sort_order":"desc"
}
response = requests.post("https://api.reporter.nih.gov/v2/projects/Search", data = params)
#print(response.status_code)
print(response.text)
Sample curl script and output:
curl -X POST "https://api.reporter.nih.gov/v2/projects/search" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"criteria\":{\"covid_response\":[\"Reg-CV\",\"CV\"]},\"include_fields\":[\"ApplId\",\"SubprojectId\",\"FiscalYear\",\"Organization\",\"ProjectNum\",\"OrgCountry\",\"ProjectNumSplit\",\"ContactPiName\",\"AllText\",\"FullStudySection\",\"ProjectStartDate\",\"ProjectEndDate\"],\"offset\":0,\"limit\":10}"