Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Multi-step operations and uploads

Some operations need more than one request: get an upload URL, then upload, then confirm; look up an ID, then act on it; create a record, then attach things to it. Use steps: instead of request:.

Steps

operations:
  upload:
    display_name: Upload a file
    side_effect: true
    params:
      - { name: channel, type: resource_locator, lookup: channels, required: true }
      - { name: binary_property, type: binary_property, default: data }
      - { name: title, type: string }
    steps:
      - id: get_url
        request:
          method: GET
          path: /files.getUploadURLExternal
          query:
            filename: "{{ binary[params.binary_property].file_name }}"
            length: "{{ binary[params.binary_property].file_size }}"
      - id: upload
        request:
          method: POST
          url: "{{ steps.get_url.body.upload_url }}"
          auth: none
          body: { encoder: raw_binary, binary_property: "{{ params.binary_property }}" }
      - id: complete
        request:
          method: POST
          path: /files.completeUploadExternal
          body:
            encoder: json
            fields:
              channel_id: "{{ params.channel }}"
              files: "{{ [ { 'id': steps.get_url.body.file_id, 'title': params.title or binary[params.binary_property].file_name } ] }}"
    output: { from_step: complete, select: "$.files", split: true }

This is the shape of an external-upload flow such as Slack’s: request a URL, upload the bytes to it without the API token, then complete the upload.

Rules:

  • Steps run in order. Each step’s response is available to later steps as steps.<id>.status, steps.<id>.headers and steps.<id>.body.

  • If a step fails (per errors), the operation fails with that step’s error; later steps do not run. A step can override errors: for itself.

  • output reads the last step’s response unless from_step names another one.

  • when: skips a step when its template is falsy:

    - id: add_labels
      when: "{{ params.labels | length > 0 }}"
      request: { method: POST, path: "/issues/{{ steps.create.body.number }}/labels", body: { encoder: json, fields: { labels: "{{ params.labels }}" } } }
    
  • A step can paginate (paginate:), for example to collect every page of IDs before acting on them.

Fan-out with for_each

for_each runs a step once per element of an array. Inside the step, each is the element and each_index its position. The step’s result in steps.<id> is then an array of responses.

steps:
  - id: create
    request:
      method: POST
      path: /lists
      body: { encoder: json, fields: { name: "{{ params.name }}" } }
  - id: add_members
    for_each: "{{ params.emails }}"
    request:
      method: POST
      path: "/lists/{{ steps.create.body.id }}/members"
      body: { encoder: json, fields: { email: "{{ each }}" } }
output:
  from_step: create
  select: "$"
  split: false

Keep fan-out bounded. If the array can be large, prefer the vendor’s batch endpoint, or let users split items upstream so each node run stays small.

Built-in upload step kinds

Large files need chunked, resumable uploads. Instead of writing the protocol out as steps, use a step kind:

KindProtocol
requestA normal request (default).
google_resumableGoogle resumable upload: initiate a session with metadata, upload in chunks, resume from the last acknowledged byte on retry.
msgraph_upload_sessionMicrosoft Graph upload session: create the session, upload byte ranges, resume on retry.
s3_multipartS3 multipart upload: initiate, upload parts, complete (or abort on failure).
steps:
  - id: upload
    kind: google_resumable
    request:
      method: POST
      url: https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable
      body:
        encoder: json
        fields:
          name: "{{ params.file_name or binary[params.binary_property].file_name }}"
          parents: "{{ [params.folder] if params.folder else none }}"
    binary_property: "{{ params.binary_property }}"
    chunk_size: 8388608
output: { select: "$", split: false }

request describes the session-initiating call; the step kind handles the chunk requests. File content is streamed from the blob store, one chunk in memory at a time. chunk_size must respect the vendor’s alignment rules (for example multiples of 256 KiB for Google).

Operations that run once per node run

By default an operation runs once per input item. Set per_item: false to run it once with all items, for batch endpoints:

operations:
  append_rows:
    display_name: Append rows
    side_effect: true
    per_item: false
    request:
      method: POST
      path: "/spreadsheets/{{ params.spreadsheet }}/values/{{ a1_range(params.sheet, 'A1') | urlencode }}:append"
      query: { valueInputOption: USER_ENTERED }
      body:
        encoder: json
        fields:
          values: "{{ items | map(attribute='values') | list }}"

items holds the JSON of every input item.