Generic function to make a POST request to the Roboflow API.
Source code in inference/core/roboflow_api.py
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855 | @wrap_roboflow_api_errors()
def post_to_roboflow_api(
endpoint: str,
api_key: Optional[str],
payload: Optional[dict] = None,
params: Optional[List[Tuple[str, str]]] = None,
) -> dict:
"""Generic function to make a POST request to the Roboflow API."""
url_params = []
if api_key:
url_params.append(("api_key", api_key))
if params:
url_params.extend(params)
full_url = _add_params_to_url(
url=f"{API_BASE_URL}/{endpoint.strip('/')}", params=url_params
)
wrapped_url = wrap_url(full_url)
headers = build_roboflow_api_headers()
response = requests.post(
url=wrapped_url,
json=payload,
headers=headers,
timeout=ROBOFLOW_API_REQUEST_TIMEOUT,
)
api_key_safe_raise_for_status(response=response)
return response.json()
|