Failed creating variable through railway API
andremaytorena
PROOP

a year ago

Hey guys, I am trying to update an environment variable using the railway api, I don't really know how the API works since I've never used graphql, I ended up with this code but I get status 400:

import json
import requests

url = 'https://backboard.railway.com/graphql/v2'
headers = {
    'Project-Access-Token': 'PROJECT_ACCESS_TOKEN',
    'Content-Type': 'application/json',
}

payload = {
  "query": """
    mutation {
      variableUpsert(
        projectId: "PROJECT_ID",
        environmentId: "ENVIRONMENT_ID",
        serviceId: "SERVICE_ID",
        name: "NEW_VARIABLE",
        value: "SECRET_VALUE"
      )
    }
  """
}

resp = requests.post(url, headers=headers, json=payload)

# 4) Check the result
try:
    resp.raise_for_status()
    print("✅ Upserted:", resp.json())
except requests.exceptions.HTTPError:
    print("HTTP", resp.status_code)
    print(resp.text)```
Solved

8 Replies

andremaytorena
PROOP

a year ago

8eca95b8-b3e6-413d-8ee9-deeebf5ebef1


andremaytorena
PROOP

a year ago

{"errors":[{"message":"Problem processing request","traceId":"6436871629412332107"},{"message":"Problem processing request","traceId":"6436871629412332107"},{"message":"Problem processing request","traceId":"6436871629412332107"},{"message":"Problem processing request","traceId":"6436871629412332107"},{"message":"Problem processing request","traceId":"6436871629412332107"},{"message":"Problem processing request","traceId":"6436871629412332107"}]}


andremaytorena
PROOP

a year ago

this is the error printed out


andremaytorena
PROOP

a year ago

Bump


andremaytorena
PROOP

a year ago

Apologies, I thought discord was only community help (replying to thread)


a year ago

Hello,

Here is the mutation and the json -

mutation VariableCollectionUpsert($projectId: String!, $serviceId: String!, $environmentId: String!, $variables: EnvironmentVariables!) {
  variableCollectionUpsert(
    input: {projectId: $projectId, environmentId: $environmentId, serviceId: $serviceId, variables: $variables}
  )
}
{
  "environmentId": "",
  "projectId": "",
  "serviceId": "",
  "variables": {
    "NEW_VARIABLE": "SECRET_VALUE"
  }
}

a year ago

Going forward, I highly recommend the explorer (3rd icon down on the left) -


a year ago

!s


Status changed to Solved brody about 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...