9 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)```
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)
9 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"
}
}9 months ago
Going forward, I highly recommend the explorer (3rd icon down on the left) -
9 months ago
!s
Status changed to Solved brody • 9 months ago