Skip to content

Commit f0c3fe4

Browse files
zimegClaude
andcommitted
fix(web-api): send blocks.validate payloads as form params
blocks.validate reads blocks/message/view as JSON-encoded form fields, not a JSON request body — a JSON body returns invalid_arguments ("must provide exactly one of blocks, view, or message"). Serialize each provided payload with json.dumps (converting Block/View objects to dicts first) and send via params, following conversations.requestSharedInvite.approve. Verified against the live API: blocks/message/view all validate, and malformed input returns the errors[] contract. client.py is the source of truth; async_client.py and legacy_client.py are regenerated via scripts/codegen.py. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
1 parent a40d04a commit f0c3fe4

3 files changed

Lines changed: 39 additions & 24 deletions

File tree

‎slack_sdk/web/async_client.py‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,14 +2244,19 @@ async def blocks_validate(
22442244
Provide exactly one of ``blocks``, ``message``, or ``view``.
22452245
https://docs.slack.dev/reference/methods/blocks.validate
22462246
"""
2247-
kwargs.update({"blocks": blocks, "message": message})
2248-
if isinstance(view, View):
2249-
kwargs.update({"view": view.to_dict()})
2250-
else:
2251-
kwargs.update({"view": view})
2252-
_parse_web_class_objects(kwargs)
2253-
kwargs = _remove_none_values(kwargs)
2254-
return await self.api_call("blocks.validate", json=kwargs)
2247+
if blocks is not None:
2248+
if isinstance(blocks, str):
2249+
kwargs.update({"blocks": blocks})
2250+
else:
2251+
kwargs.update({"blocks": json.dumps([b.to_dict() if isinstance(b, Block) else b for b in blocks])})
2252+
if message is not None:
2253+
kwargs.update({"message": message if isinstance(message, str) else json.dumps(message)})
2254+
if view is not None:
2255+
if isinstance(view, View):
2256+
kwargs.update({"view": json.dumps(view.to_dict())})
2257+
else:
2258+
kwargs.update({"view": view if isinstance(view, str) else json.dumps(view)})
2259+
return await self.api_call("blocks.validate", params=kwargs)
22552260

22562261
async def bookmarks_add(
22572262
self,

‎slack_sdk/web/client.py‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,14 +2234,19 @@ def blocks_validate(
22342234
Provide exactly one of ``blocks``, ``message``, or ``view``.
22352235
https://docs.slack.dev/reference/methods/blocks.validate
22362236
"""
2237-
kwargs.update({"blocks": blocks, "message": message})
2238-
if isinstance(view, View):
2239-
kwargs.update({"view": view.to_dict()})
2240-
else:
2241-
kwargs.update({"view": view})
2242-
_parse_web_class_objects(kwargs)
2243-
kwargs = _remove_none_values(kwargs)
2244-
return self.api_call("blocks.validate", json=kwargs)
2237+
if blocks is not None:
2238+
if isinstance(blocks, str):
2239+
kwargs.update({"blocks": blocks})
2240+
else:
2241+
kwargs.update({"blocks": json.dumps([b.to_dict() if isinstance(b, Block) else b for b in blocks])})
2242+
if message is not None:
2243+
kwargs.update({"message": message if isinstance(message, str) else json.dumps(message)})
2244+
if view is not None:
2245+
if isinstance(view, View):
2246+
kwargs.update({"view": json.dumps(view.to_dict())})
2247+
else:
2248+
kwargs.update({"view": view if isinstance(view, str) else json.dumps(view)})
2249+
return self.api_call("blocks.validate", params=kwargs)
22452250

22462251
def bookmarks_add(
22472252
self,

‎slack_sdk/web/legacy_client.py‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,14 +2244,19 @@ def blocks_validate(
22442244
Provide exactly one of ``blocks``, ``message``, or ``view``.
22452245
https://docs.slack.dev/reference/methods/blocks.validate
22462246
"""
2247-
kwargs.update({"blocks": blocks, "message": message})
2248-
if isinstance(view, View):
2249-
kwargs.update({"view": view.to_dict()})
2250-
else:
2251-
kwargs.update({"view": view})
2252-
_parse_web_class_objects(kwargs)
2253-
kwargs = _remove_none_values(kwargs)
2254-
return self.api_call("blocks.validate", json=kwargs)
2247+
if blocks is not None:
2248+
if isinstance(blocks, str):
2249+
kwargs.update({"blocks": blocks})
2250+
else:
2251+
kwargs.update({"blocks": json.dumps([b.to_dict() if isinstance(b, Block) else b for b in blocks])})
2252+
if message is not None:
2253+
kwargs.update({"message": message if isinstance(message, str) else json.dumps(message)})
2254+
if view is not None:
2255+
if isinstance(view, View):
2256+
kwargs.update({"view": json.dumps(view.to_dict())})
2257+
else:
2258+
kwargs.update({"view": view if isinstance(view, str) else json.dumps(view)})
2259+
return self.api_call("blocks.validate", params=kwargs)
22552260

22562261
def bookmarks_add(
22572262
self,

0 commit comments

Comments
 (0)