api.integrations.shopify.files

A product’s documentation PDF: uploaded to the store’s Files, then referenced by a metafield.

A PDF goes through a staged upload: ask Shopify for an upload target, post the file there, create the file from it, and wait until Shopify has processed it. Needs the read_files and write_files scopes.

Attributes

Exceptions

ShopifyFileError

A file upload or metafield write that did not complete.

ShopifyFileTooLargeError

Larger than MAX_FILE_BYTES: refused before any request.

Classes

Functions

format_megabytes(size) → str

product_gid(product_id) → str

Module Contents

api.integrations.shopify.files.logger
api.integrations.shopify.files.REQUEST_TIMEOUT_SECONDS = 60
api.integrations.shopify.files.FILE_READY_POLL_SECONDS = 1.0
api.integrations.shopify.files.FILE_READY_MAX_POLLS = 30
api.integrations.shopify.files.MAX_FILE_BYTES = 20971520
api.integrations.shopify.files.STORAGE_ERROR_HINTS
exception api.integrations.shopify.files.ShopifyFileError

Bases: api.integrations.shopify.graphql.ShopifyError

A file upload or metafield write that did not complete.

exception api.integrations.shopify.files.ShopifyFileTooLargeError

Bases: ShopifyFileError

Larger than MAX_FILE_BYTES: refused before any request.

api.integrations.shopify.files.format_megabytes(size: int) → str
api.integrations.shopify.files.product_gid(product_id: int | str) → str
class api.integrations.shopify.files.ShopifyFiles(domain: str, api_version: str, token_provider: api.integrations.shopify.auth.TokenProvider = get_shopify_access_token)
get_product_documentation(product_id: int | str, namespace: str, file_key: str, source_key: str) → tuple[str | None, str | None]

(file metafield, source metafield) currently on the product; None when unset.

upload_pdf(content: bytes, filename: str, alt: str = '') → str

Uploads a PDF to the store’s Files, waits until Shopify has processed it, and returns its id.

set_product_metafields(product_id: int | str, metafields: list[dict[str, str]]) → None

Sets {namespace, key, type, value} metafields, all or none (metafieldsSet upserts).