MCPcopy
hub / github.com/slackapi/python-slack-sdk / api_call

Method api_call

slack_sdk/web/legacy_base_client.py:103–186  ·  view source on GitHub ↗

Create a request and execute the API call to Slack. Args: api_method (str): The target Slack API method. e.g. 'chat.postMessage' http_verb (str): HTTP Verb. e.g. 'POST' files (dict): Files to multipart upload. e.g. {image OR

(
        self,
        api_method: str,
        *,
        http_verb: str = "POST",
        files: Optional[dict] = None,
        data: Union[dict, FormData] = None,
        params: Optional[dict] = None,
        json: Optional[dict] = None,
        headers: Optional[dict] = None,
        auth: Optional[dict] = None,
    )

Source from the content-addressed store, hash-verified

101 self._event_loop = loop
102
103 def api_call(
104 self,
105 api_method: str,
106 *,
107 http_verb: str = "POST",
108 files: Optional[dict] = None,
109 data: Union[dict, FormData] = None,
110 params: Optional[dict] = None,
111 json: Optional[dict] = None,
112 headers: Optional[dict] = None,
113 auth: Optional[dict] = None,
114 ) -> Union[asyncio.Future, SlackResponse]:
115 """Create a request and execute the API call to Slack.
116 Args:
117 api_method (str): The target Slack API method.
118 e.g. 'chat.postMessage'
119 http_verb (str): HTTP Verb. e.g. 'POST'
120 files (dict): Files to multipart upload.
121 e.g. {image OR file: file_object OR file_path}
122 data: The body to attach to the request. If a dictionary is
123 provided, form-encoding will take place.
124 e.g. {'key1': 'value1', 'key2': 'value2'}
125 params (dict): The URL parameters to append to the URL.
126 e.g. {'key1': 'value1', 'key2': 'value2'}
127 json (dict): JSON for the body to attach to the request
128 (if files or data is not specified).
129 e.g. {'key1': 'value1', 'key2': 'value2'}
130 headers (dict): Additional request headers
131 auth (dict): A dictionary that consists of client_id and client_secret
132 Returns:
133 (SlackResponse)
134 The server's response to an HTTP request. Data
135 from the response can be accessed like a dict.
136 If the response included 'next_cursor' it can
137 be iterated on to execute subsequent requests.
138 Raises:
139 SlackApiError: The following Slack API call failed:
140 'chat.postMessage'.
141 SlackRequestError: Json data can only be submitted as
142 POST requests.
143 """
144
145 api_url = _get_url(self.base_url, api_method)
146
147 headers = headers or {}
148 headers.update(self.headers)
149
150 if auth is not None:
151 if isinstance(auth, dict):
152 auth = BasicAuth(auth["client_id"], auth["client_secret"])
153 elif isinstance(auth, BasicAuth):
154 headers["Authorization"] = auth.encode()
155
156 req_args = _build_req_args(
157 token=self.token,
158 http_verb=http_verb,
159 files=files,
160 data=data,

Callers

nothing calls this directly

Calls 6

_sendMethod · 0.95
_sync_sendMethod · 0.95
_get_urlFunction · 0.70
_build_req_argsFunction · 0.70
_get_event_loopFunction · 0.70

Tested by

no test coverage detected