Stormkit Logo
Stormkit Logo
+ K
docsblogwhats new?FAQpricingGitHubTwitterDiscordDiscordlogin
Welcome
Getting StartedContributingContact Us
Api
AuthenticationDomainsRedirectsSnippets

Snippets API

POST /v1/snippets

Add snippets.

interface Request {
  snippets: []Snippet
}

interface Response {
  snippets: []Snippet
}
# Example

curl -X POST \
     -H 'Authorization: <api_key>' \
     -H 'Content-Type: application/javascript' \
     'https://api.stormkit.io/v1/snippets' \
     -d '{ "snippets": [{ "title": "Snippet title", "content":  "Hello World", "enabled":  true, "prepend":  false, "location": "head", "rules": { "hosts": ["example.org", "*.dev"], "path": "/my-path" } }] }'
GET /v1/snippets

Return all snippets of an environment.

interface QueryString {
  afterId?: string
  hosts?: string
}

interface Response {
  snippets: []Redirect
  pagination: Pagination
}
# Example

curl -X GET \
     -H 'Authorization: <api_key>' \
     -H 'Content-Type: application/javascript' \
     'https://api.stormkit.io/v1/snippets'
{
  "snippets": [
    {
      "id": "1501",
      "title": "Snippet title",
      "content": "Hello World",
      "enabled": true,
      "prepend": false,
      "location": "head",
      "rules": {
        "hosts": ["example.org", "*.dev"],
        "path": "/my-path"
      }
    }
  ],
  "pagination": {
    "hasNextPage": false
  }
}

To filter snippets by hosts, you can use the hosts querystring parameter. Multiple hosts should be separated by comma (,).

To paginate results, you can specify the afterId querystring parameter. This value is returned in the first GET request.

PUT /v1/snippets

Update the given snippet.

interface Request {
  snippet: Snippet
}

interface Response {
  ok: boolean
}
# Example

curl -X PUT \
     -H 'Authorization: <api_key>' \
     -H 'Content-Type: application/javascript' \
     'https://api.stormkit.io/v1/snippets' \
     -d '{ "snippet": { "id": 1501, "title": "New title", "content":  "Hello World", "enabled":  true, "prepend":  false, "location": "head", "rules": { "hosts": ["example.org", "*.dev"], "path": "/my-path" } } }'
DELETE /v1/snippets

Delete Snippets with the given ids.

interface QueryString {
  ids: []string
}

interface Response {
  ok: boolean
}
# Example

curl -X PUT \
     -H 'Authorization: <api_key>' \
     -H 'Content-Type: application/javascript' \
     'https://api.stormkit.io/v1/snippets?ids=1501,5061'

Syntax

interface Snippet {
  id: string
  title: string
  content: string
  enabled: boolean
  location: 'head' | 'body'
  prepend: boolean
  rules?: {
    hosts?: []string
    path?: string
  }
}

interface Pagination {
  hasNextPage: boolean
  afterId?: string
}
Property Definition
id The unique id of the snippet.
title The title is used internally for describing what the snippet does.
content The content that is going to be injected into the page.
enabled Whether the snippet is enabled or not.
location The injection location for the snippet.
prepend If true, the snippet will be injected as the first child to the location. Otherwise as the last child.
rules.hosts Inject snippet only for the provided hosts.
rules.path If specified, snippet will be injected only when the path matches.

Note: To inject snippets for all development endpoints, specify *.dev for the rules.hosts property. Specifying an indivual deployment endpoint will enable the snippet for all development endpoints.