Access the Railway GraphQL API with managed OAuth. Read projects, environments, services, deployments, and logs; redeploy services and change variables. Variables hold secrets. All access runs through the Maton gateway and the maton CLI.
Permissions
Scopes
Choose which of these OAuth scopes the connection asks for when you connect, or pass them as scopes to Create Connection. Always scopes are added whatever you choose, By default ones are requested when you don't choose, and Optional ones only when you choose them. See Scopes.
| Scope | Requested |
|---|---|
openid | Always |
email | Always |
profile | Always |
offline_access | Always |
workspace:viewer | Optional |
workspace:member | Optional |
workspace:admin | By default |
project:viewer | Optional |
project:member | Optional |
project:admin | By default |
notifications | Optional |
ssh_keys | Optional |
Reference
Every call is a POST to graphql/v2: https://backboard.railway.com/graphql/v2 becomes /railway/graphql/v2.
Account
Get Me
maton api -X POST '/railway/graphql/v2' -H 'Content-Type: application/json' --input - <<'JSON'
{"query": "{ me { id name email workspaces { id name } } }"}
JSONResponse:
{
"data": {
"me": {
"id": "6f1e2d3c-0000-4000-8000-000000000001",
"name": "Alex Lee",
"email": "you@example.com",
"workspaces": [{"id": "9a8b7c6d-0000-4000-8000-000000000002", "name": "Acme"}]
}
}
}workspaces lists the workspaces shared with the connection; their IDs are what projects needs.
Projects
List Projects
maton api -X POST '/railway/graphql/v2' -H 'Content-Type: application/json' --input - <<'JSON'
{"query": "query ($workspaceId: String) { projects(workspaceId: $workspaceId) { edges { node { id name environments { edges { node { id name } } } services { edges { node { id name } } } } } } }", "variables": {"workspaceId": "{workspace_id}"}}
JSONNote: {workspace_id} stands for a real value; fill it in before sending the request.
Response (trimmed):
{
"data": {
"projects": {
"edges": [
{
"node": {
"id": "2b3c4d5e-0000-4000-8000-000000000003",
"name": "acme-api",
"environments": {"edges": [{"node": {"id": "3c4d5e6f-0000-4000-8000-000000000004", "name": "production"}}]},
"services": {"edges": [{"node": {"id": "4d5e6f70-0000-4000-8000-000000000005", "name": "web"}}]}
}
}
]
}
}
}projects needs workspaceId; without it Railway answers Not Authorized. { workspace(workspaceId: "…") { projects { … } } } returns the same list. Lists are Relay connections: pass first and after, and read pageInfo { hasNextPage endCursor }.
Get a Project
maton api -X POST '/railway/graphql/v2' -H 'Content-Type: application/json' --input - <<'JSON'
{"query": "query ($id: String!) { project(id: $id) { id name description createdAt environments { edges { node { id name } } } services { edges { node { id name } } } } }", "variables": {"id": "{project_id}"}}
JSONenvironment(id: "…") and service(id: "…") read one environment or service the same way; serviceInstance(serviceId: "…", environmentId: "…") returns a service's settings in one environment (start command, replicas, region, domains, latest deployment).
Deployments
List Deployments
maton api -X POST '/railway/graphql/v2' -H 'Content-Type: application/json' --input - <<'JSON'
{"query": "query ($input: DeploymentListInput!) { deployments(input: $input, first: 5) { edges { node { id status createdAt staticUrl } } } }", "variables": {"input": {"projectId": "{project_id}", "environmentId": "{environment_id}", "serviceId": "{service_id}"}}}
JSONstatus is one of QUEUED, INITIALIZING, BUILDING, DEPLOYING, SUCCESS, FAILED, CRASHED, SLEEPING, REMOVED, and a few others. A deployment's meta (commit, image, build details) can carry build-time variable values.
Read Logs
maton api -X POST '/railway/graphql/v2' -H 'Content-Type: application/json' --input - <<'JSON'
{"query": "query ($id: String!) { deploymentLogs(deploymentId: $id, limit: 100) { timestamp severity message } }", "variables": {"id": "{deployment_id}"}}
JSONbuildLogs takes the same arguments for the build step; filter takes a Railway log filter, and startDate / endDate bound the window.
Redeploy a Service
maton api -X POST '/railway/graphql/v2' -H 'Content-Type: application/json' --input - <<'JSON'
{"query": "mutation ($environmentId: String!, $serviceId: String!) { serviceInstanceRedeploy(environmentId: $environmentId, serviceId: $serviceId) }", "variables": {"environmentId": "{environment_id}", "serviceId": "{service_id}"}}
JSONReturns true. deploymentRestart(id:), deploymentRollback(id:) (to an earlier deployment), and deploymentStop(id:) act on one deployment.
Variables
Read Variables
maton api -X POST '/railway/graphql/v2' -H 'Content-Type: application/json' --input - <<'JSON'
{"query": "query ($projectId: String!, $environmentId: String!, $serviceId: String) { variables(projectId: $projectId, environmentId: $environmentId, serviceId: $serviceId) }", "variables": {"projectId": "{project_id}", "environmentId": "{environment_id}", "serviceId": "{service_id}"}}
JSONReturns a JSON object of names to plain-text values. Without serviceId it returns the environment's shared variables.
Set a Variable
maton api -X POST '/railway/graphql/v2' -H 'Content-Type: application/json' --input - <<'JSON'
{"query": "mutation ($input: VariableUpsertInput!) { variableUpsert(input: $input) }", "variables": {"input": {"projectId": "{project_id}", "environmentId": "{environment_id}", "serviceId": "{service_id}", "name": "LOG_LEVEL", "value": "debug", "skipDeploys": true}}}
JSONReturns true. Without skipDeploys: true, the change redeploys the service. variableCollectionUpsert sets several at once; variableDelete(input: {projectId, environmentId, serviceId, name}) removes one.
Services
Create a Service
maton api -X POST '/railway/graphql/v2' -H 'Content-Type: application/json' --input - <<'JSON'
{"query": "mutation ($input: ServiceCreateInput!) { serviceCreate(input: $input) { id name } }", "variables": {"input": {"projectId": "{project_id}", "environmentId": "{environment_id}", "name": "worker", "source": {"image": "nginx:latest"}}}}
JSONsource is {"image": "…"} for a Docker image or {"repo": "owner/name"} for a GitHub repository. serviceDelete(id:) deletes a service; projectCreate, projectUpdate, environmentCreate, serviceDomainCreate, and customDomainCreate follow the same input pattern (check their fields in the schema).
Notes
- Authentication: OAuth (Login with Railway). On Railway's consent screen the user picks which workspaces and projects to share; the scopes set the role on them:
vieweris read-only,membercan deploy and edit, andadmin(the default) can also manage members and settings. A viewer connection reads projects, butvariablesand every mutation returnNot Authorized. Railway sign-ins expire after an hour, and Maton renews them. - Connection metadata: the user's
user_id,name, andemail, andgranted_scopes. - Errors: GraphQL errors come back with HTTP
200and anerrorsarray."message": "Not Authorized"(withextensions.codeINTERNAL_SERVER_ERROR) means the scope doesn't allow the call, the project wasn't shared, or a required argument such asworkspaceIdis missing. - Secrets elsewhere:
environmentPatchesshow variable values masked as*****, andprojectTokensshow onlydisplayToken. Nestedenvironment { variables { edges { node { name } } } }returns variable names only.apiTokensis refused to OAuth connections. - Schema: public; browse it at https://railway.com/graphiql or with an introspection query.
- Rate limits: 100 requests an hour on Free, 1,000 an hour on Hobby (10 a second), and 10,000 an hour on Pro (50 a second). Responses carry
X-RateLimit-Limit,X-RateLimit-Remaining, andX-RateLimit-Reset; past the limit Railway answers429withRetry-After.