Skip to content

Documentation

PHP SDK: SDK for export transformations

An export transformation uses the same run(\Sdk\Context $ctx) entry point as a collection algorithm, but with fewer available actions: network, browser, and file operations are unavailable here. Use this mode to calculate values, filter records, and reshape collected data.

Read records and return a result

The code receives records after field mapping. Call $ctx->emit() to produce the result. This example passes records through unchanged:

<?php
function run(\Sdk\Context $ctx): void
{
    foreach ($ctx->param('items', []) as $item) {
        $ctx->emit($item);
    }
}

param reads items, an array of records after field mapping. emit outputs a processed record. Handle missing input as an empty array.

Choose a processing mode

In Records mode, preserve the number and order of items. In Set mode, you can group and filter them. The maximum set is 10,000 records or 16 MB, and one invocation may run for 30 seconds. Exceeding a limit stops processing with an error.

File preparation and Webhook delivery process the complete allowed selection. An endpoint request processes only its current page. Do not present a page total as the total for the entire catalog.

Change a field

foreach ($ctx->param('items', []) as $item) {
    $item['in_stock'] = (float) ($item['quantity'] ?? 0) > 0;
    $ctx->emit($item);
}

No record is removed and order is preserved, so this example fits Records mode. A missing quantity is treated as zero; change this rule explicitly if your source works differently.

For setup, saving, and testing, see the export transformation guide.

Python and other languages

The transformation editor supports PHP, JavaScript, TypeScript, and Python independently of collection language. Save new source when changing languages. Python uses def run(ctx):, reads ctx.params().get("items", []), and emits dictionaries with ctx.emit(). Return values do not become export records. See the complete Python transformation reference. The existing PHP examples on this page retain PHP syntax.

The logical dataset cap is 16 MiB, but each serialized input/output message must also fit the 12 MiB transport limit including metadata. Effective capacity may therefore be lower. If the payload limit is reached, narrow the selection or reduce large fields; the system reports an error rather than truncating data.