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)```8 Replies
{"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"}]}
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