Aug-01-2023, 10:14 AM
As you are using the requests library in Python to make a POST request to the NFIB SBET API. The 400 response you are getting indicates that there is likely an issue with the request you are sending to the API.
Data parameter should contain a JSON object with the request parameters. However, in your code, you are using the data parameter to send the JSON data. To properly send the JSON data, you should use the json parameter instead.
Data parameter should contain a JSON object with the request parameters. However, in your code, you are using the data parameter to send the JSON data. To properly send the JSON data, you should use the json parameter instead.
import requests import json url = "http://open.api.nfib-sbet.org/rest/sbetdb/_proc/getIndicators" headers = { "Content-Type": "application/json", "app_name": "sbet" } data = { "params": [ { "name": "minYear", "param_type": "IN", "value": 2010 }, { "name": "minMonth", "param_type": "IN", "value": 6 }, { "name": "maxYear", "param_type": "IN", "value": 2010 }, { "name": "maxMonth", "param_type": "IN", "value": 12 }, { "name": "indicator", "param_type": "IN", "value": "OPT_INDEX" } ] } response = requests.post(url, headers=headers, json=data) print(response.status_code) print(response.json())By using the json parameter instead of the data parameter, the requests library will automatically set the Content-Type header to "application/json" and encode the JSON data correctly.