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

Method api_call

slack_sdk/web/async_base_client.py:102–179  ·  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 O

(
        self,
        api_method: str,
        *,
        http_verb: str = "POST",
        files: Optional[dict] = None,
        data: Optional[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

100 # api call
101
102 async def api_call(
103 self,
104 api_method: str,
105 *,
106 http_verb: str = "POST",
107 files: Optional[dict] = None,
108 data: Optional[Union[dict, FormData]] = None,
109 params: Optional[dict] = None,
110 json: Optional[dict] = None,
111 headers: Optional[dict] = None,
112 auth: Optional[dict] = None,
113 ) -> AsyncSlackResponse:
114 """Create a request and execute the API call to Slack.
115
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
133 Returns:
134 (AsyncSlackResponse)
135 The server's response to an HTTP request. Data
136 from the response can be accessed like a dict.
137 If the response included 'next_cursor' it can
138 be iterated on to execute subsequent requests.
139
140 Raises:
141 SlackApiError: The following Slack API call failed:
142 'chat.postMessage'.
143 SlackRequestError: Json data can only be submitted as
144 POST requests.
145 """
146
147 api_url = _get_url(self.base_url, api_method)
148 if auth is not None:
149 if isinstance(auth, Dict):
150 auth = BasicAuth(auth["client_id"], auth["client_secret"]) # type: ignore[assignment]
151 if isinstance(auth, BasicAuth):
152 if headers is None:
153 headers = {}
154 headers["Authorization"] = auth.encode()
155 auth = None
156
157 headers = headers or {}
158 headers.update(self.headers)
159 req_args = _build_req_args(

Callers

nothing calls this directly

Calls 4

_sendMethod · 0.95
_get_urlFunction · 0.70
_build_req_argsFunction · 0.70

Tested by

no test coverage detected