Failed creating variable through railway API
andremaytorena
PROOP

10 months 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:

```py
import json
import requests

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

payload = {
"query": """
mutation {
variableUpsert(
projectId: "PROJECTID", environmentId: "ENVIRONMENTID",
serviceId: "SERVICEID", name: "NEWVARIABLE",
value: "SECRET_VALUE"
)
}
"""
}

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

4) Check the result

try:
resp.raiseforstatus()
print("✅ Upserted:", resp.json())
except requests.exceptions.HTTPError:
print("HTTP", resp.status_code)
print(resp.text)```

Solved

8 Replies

andremaytorena
PROOP

10 months ago

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


andremaytorena
PROOP

10 months 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

10 months ago

this is the error printed out


andremaytorena
PROOP

10 months ago

Bump


andremaytorena
PROOP

10 months ago

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


10 months 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"
  }
}

10 months ago

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


10 months ago

!s


Status changed to Solved brody 10 months ago


Loading...