Functions belong to an organization. Choose the organization whose permissions,
API keys, and spending should apply. The examples use acme; replace it with
your organization slug. See
authentication to sign in first.
Create and list functions
Section titled “Create and list functions”Open Functions in your organization. Enter a name in Create a function and submit the form. Your function appears in the list; open it to edit its draft.
curl https://api.str.ing/acme/functions \ -H "Authorization: Bearer $STRING_TOKEN" \ -H 'Content-Type: application/json' \ -d '{"name":"Classify support tickets"}'
curl https://api.str.ing/acme/functions \ -H "Authorization: Bearer $STRING_TOKEN"Use the returned slug or ID in the {function} position of a request path.
str api '/{org}/functions' -d '{"name":"Classify support tickets"}'str api '/{org}/functions'{org} expands to the organization chosen during str login. Use the function’s
returned slug or ID in subsequent requests.
Save a draft
Section titled “Save a draft”A draft is your editable function source. Saving a draft leaves published versions
unchanged. function.json declares schemas and configuration; prompt functions
use prompt.hbs, and TypeScript scripts use main.ts.
Open the function from the Functions list. Select a source file to edit it, then save the draft. If another edit conflicts with yours, review the latest saved draft and reconcile your changes before saving again.
Read the draft, then replace its complete source tree:
curl https://api.str.ing/acme/functions/classify-support-tickets/draft \ -H "Authorization: Bearer $STRING_TOKEN"
curl -X PUT https://api.str.ing/acme/functions/classify-support-tickets/draft \ -H "Authorization: Bearer $STRING_TOKEN" \ -H 'Content-Type: application/json' \ -d @draft.jsonIn draft.json, set base_commit to the commit returned by the read, and
files to an object mapping each file path to its text. Before the first save,
the commit is null. Include every file you intend to keep.
A stale base_commit returns 409 DRAFT_CONFLICT. Read the latest draft and
reconcile your edits before saving again.
str api '/{org}/functions/classify-support-tickets/draft'str api -X PUT '/{org}/functions/classify-support-tickets/draft' -d @draft.jsonIn draft.json, set base_commit to the commit from the draft read and files
to an object mapping file paths to their text. Use a null base_commit for the
first save. Include every file you intend to keep.
If saving returns 409 DRAFT_CONFLICT, read the latest draft and reconcile your
changes before trying again.
Saving does not execute the function. The API specification describes accepted source files and the script-check endpoint.
Publish a version
Section titled “Publish a version”Published versions are immutable. Publish a saved draft commit under a new version to make a change. A publish preview compares your schemas and suggests versions.
Use curl or str api to publish a saved draft. Select either option above for
the preview and publish requests.
Replace YOUR_COMMIT with the commit returned by your draft save:
curl 'https://api.str.ing/acme/functions/classify-support-tickets/publish-preview?commit=YOUR_COMMIT' \ -H "Authorization: Bearer $STRING_TOKEN"
curl https://api.str.ing/acme/functions/classify-support-tickets/versions \ -H "Authorization: Bearer $STRING_TOKEN" \ -H 'Content-Type: application/json' \ -d '{"commit":"YOUR_COMMIT","version":{"major":1,"minor":0,"patch":0}}'Choose an exact version allowed by the preview.
Replace YOUR_COMMIT with the commit returned by your draft save:
str api '/{org}/functions/classify-support-tickets/publish-preview?commit=YOUR_COMMIT'str api '/{org}/functions/classify-support-tickets/versions' \ -d '{"commit":"YOUR_COMMIT","version":{"major":1,"minor":0,"patch":0}}'Choose an exact version allowed by the preview.
Select a default version
Section titled “Select a default version”Publishing leaves the default unchanged. Select a published version explicitly, or clear the default when you no longer want one.
Use curl or str api to select or clear the default version.
curl -X PUT https://api.str.ing/acme/functions/classify-support-tickets/default-version \ -H "Authorization: Bearer $STRING_TOKEN" \ -H 'Content-Type: application/json' \ -d '{"version":{"major":1,"minor":0,"patch":0}}'Send {"version":null} to clear the default. The response includes the previous
default so you can restore it.
str api -X PUT '/{org}/functions/classify-support-tickets/default-version' \ -d '{"version":{"major":1,"minor":0,"patch":0}}'Send -d '{"version":null}' instead to clear the default. The response includes
the previous default so you can restore it.
Publishing and selecting a default do not execute the function.