Skip to content

feat: Add validate_input endpoint #396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/apify_client/clients/resource_clients/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,31 @@ def webhooks(self) -> WebhookCollectionClient:
"""Retrieve a client for webhooks associated with this Actor."""
return WebhookCollectionClient(**self._sub_resource_init_options())

def validate_input(
self, run_input: Any = None, *, build_tag: str | None = None, content_type: str | None = None
) -> bool:
"""Validate an input for the Actor that defines an input schema.

Args:
run_input: The input to validate.
build_tag: The actor's build tag.
content_type: The content type of the input.

Returns:
True if the input is valid, else raise an exception with validation error details.
"""
run_input, content_type = encode_key_value_store_record_value(run_input, content_type)

self.http_client.call(
url=self._url('validate-input'),
method='POST',
headers={'content-type': content_type},
data=run_input,
params=self._params(build=build_tag),
)

return True


class ActorClientAsync(ResourceClientAsync):
"""Async sub-client for manipulating a single Actor."""
Expand Down Expand Up @@ -829,3 +854,28 @@ def version(self, version_number: str) -> ActorVersionClientAsync:
def webhooks(self) -> WebhookCollectionClientAsync:
"""Retrieve a client for webhooks associated with this Actor."""
return WebhookCollectionClientAsync(**self._sub_resource_init_options())

async def validate_input(
self, run_input: Any = None, *, build_tag: str | None = None, content_type: str | None = None
) -> bool:
"""Validate an input for the Actor that defines an input schema.

Args:
run_input: The input to validate.
build_tag: The actor's build tag.
content_type: The content type of the input.

Returns:
True if the input is valid, else raise an exception with validation error details.
"""
run_input, content_type = encode_key_value_store_record_value(run_input, content_type)

await self.http_client.call(
url=self._url('validate-input'),
method='POST',
headers={'content-type': content_type},
data=run_input,
params=self._params(build=build_tag),
)

return True