MCPcopy Create free account
hub / github.com/openai/plugins / api_request

Function api_request

plugins/box/skills/box/scripts/box_rest.py:31–60  ·  view source on GitHub ↗
(
    method: str,
    url: str,
    token: str,
    body: bytes | None = None,
    headers: dict[str, str] | None = None,
)

Source from the content-addressed store, hash-verified

29
30
31def api_request(
32 method: str,
33 url: str,
34 token: str,
35 body: bytes | None = None,
36 headers: dict[str, str] | None = None,
37) -> Any:
38 req = request.Request(
39 url=url,
40 method=method,
41 data=body,
42 headers=build_headers(token, headers),
43 )
44 try:
45 with request.urlopen(req) as resp:
46 raw = resp.read()
47 content_type = resp.headers.get("Content-Type", "")
48 if "application/json" in content_type:
49 return json.loads(raw.decode("utf-8"))
50 return {"status": resp.status, "body": raw.decode("utf-8")}
51 except error.HTTPError as exc:
52 raw = exc.read().decode("utf-8", errors="replace")
53 try:
54 payload = json.loads(raw)
55 except json.JSONDecodeError:
56 payload = {"message": raw}
57 payload["_http_status"] = exc.code
58 raise SystemExit(
59 f"Box API error {exc.code}:\n{json.dumps(payload, indent=2, sort_keys=True)}"
60 )
61
62
63def dump_json(payload: Any) -> None:

Callers 7

handle_get_itemFunction · 0.70
handle_get_folder_itemsFunction · 0.70
handle_searchFunction · 0.70
handle_create_folderFunction · 0.70
handle_upload_fileFunction · 0.70
handle_move_itemFunction · 0.70

Calls 2

build_headersFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected