Documentation / How-to guides
Call an external API and publish your own
Connect to an external REST API with an integration, and expose server actions as REST operations with a published service.
Applies to Glyphox 1.0.10
An integration describes an external REST API once: its address, how to authenticate and its endpoints. Every action of the module can then call an endpoint by name. A published service works in the other direction: it gives your server actions REST addresses that other systems can call.
Step 1: Create the integration
Run Glyphox: New Integration. To start from a description that already lists the endpoints, run Glyphox: Add Connector from Template… and select Slack, GitHub, Jira Cloud, Stripe, SendGrid, Twilio, S3-compatible storage, an OpenAI-compatible LLM API or a generic webhook.
The integration opens in its editor and is listed in the module's APIs group in the Solution tree. Set its Integration name and Base URL.
Step 2: Set the authentication
Select Authentication: None, Bearer token or API key. For an API key, set API key name, for example X-API-Key, and Send in: Header or Query.
The credential is a secret and is never stored in the model. It is listed in Module Settings → Secrets under the integration's name, for example STRIPE_API_KEY for an integration named Stripe that uses an API key, or SLACK_TOKEN for one named Slack that uses a bearer token. Set its value there for runs on this computer, and enter it under Solution Settings → Environments → Sealed secrets for a deployment.
A page that calls an authenticated integration does so through the module's server, which attaches the credential, so the credential never reaches the browser.
Step 3: Describe the endpoints
Select Add endpoint and set its Method, Name and Path, relative to the base URL, such as /customers/{id}. Import from cURL creates an endpoint from a cURL command copied from the provider's documentation. A header that appears to hold a credential is left out, because the credential belongs in Authentication.
Under Parameters, select Add parameter for each value the endpoint takes, and set its Data type, whether it is Required or Optional, its Default value and where it is sent:
{name} in the path. A {name} in the path becomes a parameter automatically, and a path parameter is always required.An optional parameter with no value is left out of the request. Renaming a parameter updates the path and every step that passes a value to it.
Step 4: Call an endpoint from an action
Add a Call step to an action. Under Calls, the endpoints are grouped by integration, for example under APIs · Stripe. Select an endpoint, give each parameter a value, and set Output variable to receive the response.
You can also drag the integration from the Solution tree onto the action's canvas.
Publish your own REST operations
Run Glyphox: New Published Service and set the service's Name and Base path, for example /api/v1/orders. The service is listed in the module's APIs group.
Select Add operation for each address. An operation has a method, a path relative to the base path, such as /{id}, and Runs action: the server action that runs when the operation is called. The request's path parameters, query and body are passed to the action as its inputs, and the action's result is the response, as JSON.
An operation can instead run a runtime agent. The request body becomes the run's inputs, and the response gives the run's status and result.
Answer with a redirect
For an operation that a browser reaches, such as a form submission or a provider's return address, set Answers to Redirect to…. Enter a path from the application's root or an http(s) URL. A :name segment takes a value from the action's result or the request's inputs, and Add query value adds a value to the query string. The status is 303 See Other after a POST and 302 Found otherwise, unless you select another.
Who may call an operation
An operation applies the rule of the action it runs, set under Who may call it in the action's properties. The article Roles and permissions, under How-to guides, describes the rules.
A browser that follows a link or a redirect carries no sign-in token, so an operation that answers with a redirect normally runs an action whose rule is Anyone. The Problems view warns when it does not.
If a step fails, see Troubleshoot the first run or contact support.