Skip to content

Documentation

TypeScript SDK: Sources, files, mail, and Wildberries

This article shows how to combine several SDK parts in one scenario. For arguments, return values, and an example of every method, see KeyValue, Sources, Storage, Mail, and Wildberries.

You can request several websites and process an email in one run. Results are stored under the site selected for the scenario. Step-by-step example.

These methods connect a scenario to configured sources. Access depends on scenario settings and workspace permissions. Service calls are asynchronous; use await.

State and inputs

ctx.state().get(key, fallback), set(key, value), and incr(key, by) preserve a cursor between runs. ctx.sources().input(key) reads a configured input, document(key, id) returns a document, and comparePrices(sources) compares prices locally. Comparison requires 2–10 sources, one currency, and { sku, price, currency } records in each source.

async function run(ctx: Akmelo.Context): Promise<void> {
  const lastPage = await ctx.state().get('page', 0);
  ctx.log(`Next page: ${lastPage + 1}`);
  await ctx.state().set('page', lastPage + 1);
}

Files and mail

ctx.storage(code) works with a selected storage connection: putFromUrl(url, key, mime), put(key, content, mime), exists(key), and url(key, ttlSeconds). ctx.mail() provides available(), current(), text(), attachments(), document(id), and attachment(id) for incoming mail. Use await for these calls; do not log secrets or message contents.

Wildberries

ctx.wildberries().products(), regions(), categoryQuery(), and maxPages() read scenario settings locally. cards(ids, regionId), search(regionId, page), analogs(regionId), details(id), and detailsMany(ids) retrieve data through the ready-made source. title(card) and characteristics(card) extract local card fields. Choose a region from regions() and pass its ID to search and card methods.

async function run(ctx: Akmelo.Context): Promise<void> {
  const wb = ctx.wildberries();
  const region = wb.regions()[0];
  if (!region) ctx.abort('Choose a region');
  const cards = await wb.cards(wb.products(), region.id);
  for (const card of cards) ctx.emit({ id: card.id, title: wb.title(card) }, String(card.id));
}

Use the document SDK for Excel, PDF, Word, and CSV. Use AI for unstructured data.