PixieBrix Docs
Ask or search…
⌃K
Links
Comment on page

Val Town

Val Town

​Val Town is a service for running lightweight Javascript/Typescript code blocks in the cloud.

Running Web API Vals from PixieBrix

Val Town’s Web API lets you expose Vals as standard API endpoints.

Locate the Val Web API Endpoint

In Val Town, click the Val’s three-dot menu and copy the web endpoint:

Call the Val Web API Endpoint from PixieBrix

In PixieBrix, add the HTTP Request and call the Val’s Web API endpoint as a standard API:
  • URL: the Web API endpoint
  • Method: refer to the Val for allowed methods
  • Search Parameters: refer to the Val for available search/query parameters
  • Headers: refer to the Val for the required/optional headers
  • JSON Data: refer to the Val for the JSON payload

Running Vals from PixieBrix

Val Town’s Run API lets you run any Val as an API

Locate the Val Run API Endpoint

In Val Town, use the three-dot menu to Endpoints > Copy run endpoint

Construct the Args Payload

If your Val expected arguments, you must construct the arguments for the call. The Run Endpoint expects an array of arguments.
In PixieBrix, there are two bricks available for creating a JSON array payload:
  • Parse JSON
  • jq - JSON processor brick
For example, to construct a hard-coded payload with the jq brick:
Constructing a hard-coded payload with the jq brick

Calling the Unlisted/Public Val

To make a request to the Run endpoint for a Val, add the HTTP Request. Configure the HTTP Request brick:
  • URL: the URL for the Run endpoint for your val
  • Method: post
  • JSON Data: add an args property, and pass the array of arguments
Passing arguments to the Val Run API

Making Authenticated Requests

📚 For general information on configuring integrations, see Configuring Integrations​
To make a request to a private Val, you must pass your Val Town API Token with the request.

Configuring a Val Town Integration in PixieBrix

To set up a cloud integration that your team can access, head to the Admin Console. (If you'd rather set up something locally, use the Extension Console. Learn more about Configuring Integrations.)
From the Integrations section in the Admin or Extension Console, click the + Add Integration button in the top right corner.
Search for and select the Val Town integration.
Configure the Val Town integration, providing your Val Town API Token from https://docs.val.town/api/authentication

Locate the Val Run API Endpoint

In Val Town, copy the run fetch or express fetch endpoint for the val
From the copied endpoint, note the:
  • URL
  • Method
fetch("<https://api.val.town/v1/run/twschiller.emailMe>", {
method: "GET",
headers: { Authorization: "REDACTED" }, // DO NOT PUBLISH THIS AUTHENTICATION KEY
});

Call the Private Val

In the PixieBrix Page Editor, add the HTTP Request brick, and provide the following information:
  • URL: the URL for the Val
  • Integration Configuration: the integration you configured
  • Method: the HTTP method copied from the endpoint