Outbound HTTP from scripts

A script can call an HTTPS endpoint outside Vectros with vectros.http.request. The call goes to a destination, an address an account owner declares, and it is made only by a script version that declares the operation and that an account owner has approved for that destination.

The pieces

PieceWhat it is
DestinationA named address (alias) an account owner declares in the developer portal: its https base address, the methods it accepts, the app contexts whose scripts may call it, and the credential it sends.
SecretA named credential value an account owner stores; a destination refers to it by name.
ApprovalAn account owner's approval of one script version, by the hashes of its source and of its declared operations, to call one destination. Changing the destination's base address or methods needs a new approval.
DeclarationThe script version's optInOperations list, which must contain http.request.

Vectros adds the credential to the call; the script does not receive it.

A secret's value is entered once. The portal, the CLI and the API do not return it after it is stored.

The real controls are your approval of the destination and the approval of each script version.

How to call a destination

  1. Sign the waiver and declare the destination. In the developer portal, an account owner opens Script access (the Script outbound access page), signs the outbound call waiver for the environment, and adds the destination, bound to the app context the script runs in.

  2. Push the script version declaring the operation:

    vectros scripts push <name> --context <context> --source-file ./script.js --opt-in-operation http.request
    

    Declaring it needs the script-egress-declare capability (see the identity and access reference).

  3. Approve that version for the destination. An account owner runs:

    vectros scripts approve <name> --context <context> --destination <alias>
    

    The command shows the version, the SHA-256 of its source, the operations it declares and what changed since the version last approved for that destination, then asks before it writes. Without --script-version it approves the newest version.

  4. Call the destination from the script:

    const reply = vectros.http.request('billing-api', {
      method: 'POST',
      path: '/v1/invoices',
      headers: { 'x-request-source': 'vectros-trigger' },
      body: { customerId: input.record.customerId },
    });
    if (reply.status >= 300) throw new Error('billing-api answered ' + reply.status);
    const invoice = JSON.parse(reply.body);
    

A trigger rule that lists its own operations must list http.request too.

Blueprints

blueprint apply declares and checks only: it never creates a destination or an approval, and a blueprint never carries a credential. When no approval exists it prints needs approval with the exact vectros scripts approve ... command (see Blueprints).

vectros.http.request(alias, options)

OptionTypeDefaultNotes
methodstringGETOne of GET, POST, PUT, PATCH, DELETE, and allowed by the destination.
pathstringrequiredStarts with /; appended to the destination's base address. No ?, #, //, . or .. segments, whitespace or non-ASCII characters: put parameters in query.
queryobject{}Values are strings, numbers or booleans.
headersobject{}Values are strings, numbers or booleans. Some header names are reserved by the platform: a call that sets one fails with 400, and the message names the header (for example header not allowed: <name>); Set-Cookie headers in a reply are dropped.
bodystring, object or arraynoneAn object or array is sent as JSON, with Content-Type: application/json unless you set one. Only POST, PUT and PATCH may carry a body.
allowTruncatedbooleanfalseAccept the first part of a response longer than the platform reads.

Any other option is refused. The call returns { status, headers, body, truncated } for every completed exchange, whatever its status: a 404 or a 500 from the destination is returned to the script, not thrown. body is a string (parse JSON yourself), and header names are lowercase.

Calls go over https on port 443 only, to the address you declared, and are not redirected.

Limits

LimitValue
Calls per executionEach execution of a script may make at most 20 http.request calls.
Request bytes per executionThe requests of one execution may carry at most 256 KiB of request bytes in total.
Response bytes per executionThe responses of one execution may total at most 4 MiB.
Request body per call65,536 bytes
Response read per call1,048,576 bytes

Only request bodies count toward the request bytes, and a call's body is counted once the call is attempted, whether or not it completes. Each call also counts as one of the execution's host calls.

Errors

A refused or failed call throws an error the script can catch. Its message is the text below; on the rows marked prefixed, it reads Request failed with status <status>: <text>.

StatusTextWhen
429 prefixedThis execution has made its 20 http.request calls.A 21st call.
429 prefixedThis execution has used its budget of 262144 request bytes.The call's body would pass the request budget.
429 prefixedThis execution has read its budget of 4194304 response bytes.The responses read so far pass the response budget.
400 prefixedA destination alias is required., Unknown member '<name>'. Expected: method, path, query, headers, body, allowTruncated., path is required., body must be a string, an object or an array. and the other option checksThe alias is missing, or an option is unknown, missing or of the wrong type.
400The reason, for example path must start with /, this method carries no body, request body exceeds 65536 bytesA request the platform will not send.
400destination is unreachableThe destination's stored address can no longer be used, or its host name does not resolve to an address the platform will call.
403 prefixed'http.request' is not permitted for script <name> version <n> and this destination.The alias names no active destination, or the waiver, the destination or the approval does not permit the call.
403 prefixedThe destination's authentication failed.The destination's credential cannot be added to the call.
400The destination's authentication failed.The query is too long once the destination's credential is added to it.
408the destination did not answer in timeThe execution's time ran out during the call.
413the response is longer than 1048576 bytes; pass allowTruncated: true to accept the first partA longer response without allowTruncated.
502destination is unreachableThe connection failed.
500 prefixedThe call could not be completed.A platform fault.
503 prefixedThe destination's credential could not be used.A platform fault.

Credentials in responses

Before your script sees a response, Vectros replaces every exact copy of a credential it sent in that call with [redacted], in the response headers and body. This is a safeguard with stated limits, not a guarantee.

  • It matches exact copies only: a partial, re-encoded or hashed echo, or a value split across chunks, may not be caught.
  • A credential form shorter than 8 characters is not matched. A shorter secret can still be stored and used.
  • The forms matched are the raw value, the full header value (such as Bearer ..., and the base64 form for Basic), and the URL-encoded query value.

Repeated calls

A trigger can run a script more than once for one event, so a destination can receive the same call more than once. For example, when the script's writes meet another write to the same item, the trigger runs the script again a few seconds later, up to twice, and a trigger that still fails is retried later. Each call carries an Idempotency-Key made from the event, the call's position in the run, and the call's destination name (the alias the script calls, not the address it points to), method, path, query and body. Headers are not part of it. A repeat of the same call carries the same key, so a destination that honours it can recognise the repeat; a call whose destination name, method, path, query or body changed carries a new key. A body that differs on every run, such as one holding the current time or a random id, therefore carries a new key every time and cannot be recognised as a repeat: keep such values out of the body if the destination relies on the key. Design the destination to accept a repeated call.