Can't use api
tedimcboy
PROOP

a year ago

Hi, im trying to access the api and every time I attempt to get any data, it fails. I even went down to just using a simple request of:

curl -X POST "https://backboard.railway.app/graphql/v2" \
-H "Authorization: Bearer " \
-H "Content-Type: application/json" \
-d '{"query":"{ teams { edges { node { id name } } } }"}'

which just returns:
{"errors":[{"message":"Problem processing request","traceId":"2465529011854378178"}]}

what I am trying to do is create a new project in code via the api, here is the trace id for that issue:

Failed to create Railway project: {"errors":[{"message":"Problem processing request","traceId":"8029408264068798315"}]}

this as well fials with:
curl -X POST "https://backboard.railway.app/graphql/v2" \
-H "Authorization: Bearer " \
-H "Content-Type: application/json" \
-d '{"query":"{ projects { edges { node { id name } } } }"}'
{"errors":[{"message":"Not Authorized","locations":[{"line":1,"column":3}],"path":["projects"],"extensions":{"code":"INTERNALSERVERERROR"},"traceId":"7916032313808354165"}],"data":null}

API key works for __schema but fails for viewer and teams, Is there an internal issue causing viewer and teams queries to fail?
I confirmed the api key is functional so not sure whats wrong here. I was initally on the hobby plan and I just upgraded to pro and created a new api key tied to the team but it's still not working. Any ideas as to why? I can understand issues with creating a new project but even something as simple as pulling team info is fialing so not sure whats wrong here. ANy help would be greatl appreciated,

thanks!

Solved

119 Replies

tedimcboy
PROOP

a year ago

N/A


tedimcboy
PROOP

a year ago

Why would i not have authorization to even pull projects or team info? checked out the graphql collection as well as api reference docs but nothing seems to work other than verifying the schema. both personal tokens and team tokens are failing to let me do anything. the end goal is to be able to create. aproject from the api but for whatever reason i can't even pull basic info. can't even get my team id to test other queries lol. I am the Team owner and for a personal token it shouldn't matter what my status is given i created all the projects

i can login via the CLI and even create projects but for whatver reason i can't use the public api

quick update, i can use the query to get info about me but nothing with listing teams

curl --request POST \
--url https://backboard.railway.com/graphql/v2 \
--header 'Authorization: Bearer ' \
--header 'Content-Type: application/json' \
--data '{"query":"query { me { name email } }"}'
{"data":{"me":{"name":"","email":""}}}

curl --request POST \
--url https://backboard.railway.com/graphql/v2 \
--header 'Authorization: Bearer ' \
--header 'Content-Type: application/json' \
--data '{"query":"query { teams { edges { node { id name slug } } } }"}'
{"errors":[{"message":"Problem processing request","traceId":"4606775326853245574"}]}


tedimcboy
PROOP

a year ago

im happy to provide more trace ids if needed


brody
EMPLOYEE

a year ago

for the me and teams query you need to use the person token, a team scoped token will not work for those because the data returned is specific to your personal account, not the team workspace


tedimcboy
PROOP

a year ago

i tried the personal for teams query as well, i'll run again to test


tedimcboy
PROOP

a year ago

curl --request POST \
--url https://backboard.railway.com/graphql/v2 \
--header 'Authorization: Bearer ' \
--header 'Content-Type: application/json' \
--data '{"query":"query { teams { edges { node { id name slug } } } }"}'
{"errors":[{"message":"Problem processing request","traceId":"89861974283891367"}]}


tedimcboy
PROOP

a year ago

the me query works fine with that token though. I must be calling something wrong idk


brody
EMPLOYEE

a year ago

then it's likely the query is incorrect


tedimcboy
PROOP

a year ago

do you see anything wrong with that query? been at this for a little while and not sure whats incorrect. was going to ask for assistance with the project creation via public api but did not think i'd have toruble with even fetching simple info lol


tedimcboy
PROOP

a year ago

this worked:

curl --request POST \
--url https://backboard.railway.com/graphql/v2 \
--header "Authorization: Bearer " \
--header "Content-Type: application/json" \
--data '{"query":"query { projects { edges { node { id name } } } }"}'


brody
EMPLOYEE

a year ago

graphql is tricky and our API especially doesn't give back useful errors.

looks like you're passing in query but no variables for some of these


tedimcboy
PROOP

a year ago

being able to fetch projects is a start, but of course project creation still isn't playing too nice.


tedimcboy
PROOP

a year ago

lol yeah was quesitoning my life for a min getting back the same error for everything


tedimcboy
PROOP

a year ago

would you be able to look into this trace id?

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

used the same api key that worked with listing teams so of course the issue is the query, but was wondering if maybe it returned any more useful data on what would be wrong on your end?


tedimcboy
PROOP

a year ago

this is what i get when trying to cretae a project in code


tedimcboy
PROOP

a year ago

ain't no way i was using the wrong endpoint on that run, gonna play around with it for a sec


tedimcboy
PROOP

a year ago

here, this is the latest one using the correct endpoint and api key:

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


brody
EMPLOYEE

a year ago

Honestly, I wouldn't know where to even go to look into that trace Id, instead id just get you the correct query, but that would have to wait until I'm back at the laptop later tonight


tedimcboy
PROOP

a year ago

thats fair, yeah i'll be around. Can show you the code im running and maybe you can see what im missing in plain sight lol


tedimcboy
PROOP

a year ago

what time zone are you in? i can just post the code snippet now if it's super late for me when you're back


tedimcboy
PROOP

a year ago

alos i appreciate the help, you've helped me that last couple times i had issues like a year ago


tedimcboy
PROOP

a year ago


tedimcboy
PROOP

a year ago

all those variables do have values by the way, none of the vaariable vals are passed in as null so im guessing the quieres are just jacked up


brody
EMPLOYEE

a year ago

I'm EST, it's 6:30pm here


tedimcboy
PROOP

a year ago

ah nice same here


brody
EMPLOYEE

a year ago

then I'll message back when I'm back at my laptop


tedimcboy
PROOP

a year ago

all good! i figured it out 🙂 sorry to waste your time


tedimcboy
PROOP

a year ago

im sstill working on linking the repo to the build but i got the deployments going from code and from cli


brody
EMPLOYEE

a year ago

what was wrong?


tedimcboy
PROOP

a year ago

was infact the structure of the query initially but even then it was blocking me from making requests on both personal and teams. Didnn't even show i had a team (likely becuase i just create d ateam recently), created fresh keys again and it worked


tedimcboy
PROOP

a year ago

well one minor thing, it doesn't seem to let me link a repo when deploying a service through code, not sure as to why


brody
EMPLOYEE

a year ago

the cli creates a service and links a repo, you could just copy paste the graphql query it uses?


brody
EMPLOYEE

a year ago


tedimcboy
PROOP

a year ago

i used that query which worked great and api is indicating services are being created but there is nothing in the UI, is there usually a delay or anything? or does service creation require additional fields for it to actually show in the ui despite the pai indicating it functions

this is what i ran:

mutation { serviceCreate( input: { name: "panera-bread-service", projectId: "cc244b86-da17-4e52-9f9e-1214bd412707", environmentId: "default", source: { repo: "Talktrain/Panera_Bread_fork" }, branch: "main", variables: { POSTGRES_DATABASE_URL: "postgres://user:pass@host/db", REDIS_URL: "redis://host", CUSTOM_ENV_VAR: "value" } } ) { id name } }

1317862394135056600
1317862394621329400
1317862394852151300


tedimcboy
PROOP

a year ago

also the panera bread is just a random name for tesitng lol. It's not exactly critical that it shows in the UI but it would be extremely useful for logs and all that. Im not sure if the ui is bugging or if the service is somehow not setup correctly despite the api confirming everything is good


tedimcboy
PROOP

a year ago

ah nevermind! created the service swith the environmentid and all set!


brody
EMPLOYEE

a year ago

yeah you used default as the environment id


tedimcboy
PROOP

a year ago

i got all that working. do you have docs on creating AND deploying a redis and postgre service?

i used this to try to deploy it from docker but it always fails saying: redis 22:00:30.30 ERROR ==> The REDISPASSWORD environment variable is empty or not set. Set the environment variable ALLOWEMPTY_PASSWORD=yes to allow the container to be started with blank passwords. This is recommended only for development.

mutation {
serviceCreate(input: {
projectId: "eee53604-9d98-4e70-bca6-cba77b750ba7",
environmentId: "d5441c2b-827f-4454-b578-16c8e3358739",
name: "redis-service",
source: {
image: "bitnami/redis:7.2.5"
}
}) {
id
name
}
}

and this to mount a volume:
mutation {
volumeCreate(input: {
projectId: "eee53604-9d98-4e70-bca6-cba77b750ba7",
environmentId: "d5441c2b-827f-4454-b578-16c8e3358739",
serviceId: "689df87d-fbb2-436a-bc7a-949d87efa414",
mountPath: "/bitnami"
}) {
name
}
}


tedimcboy
PROOP

a year ago

this is the last last step i need to be done with all the api stuff


tedimcboy
PROOP

a year ago

or if you have the query handy that would be fantastic. seems that the railway automates a whole ton and its difficult to do from the public api


tedimcboy
PROOP

a year ago

im trying in graphql but nothing is working


tedimcboy
PROOP

a year ago

i assume i need the template ids like:

"d9c1a8ef-33f0-485c-9770-28b3b9598db7", # Redis Template ID

for redis but that also fails. docs have not been that useful unforch


tedimcboy
PROOP

a year ago

also tried the below which fails:

mutation {
variableCollectionUpsert(input: {
projectId: "eee53604-9d98-4e70-bca6-cba77b750ba7",
environmentId: "d5441c2b-827f-4454-b578-16c8e3358739",
serviceId: "689df87d-fbb2-436a-bc7a-949d87efa414 ",
variables: [
{ name: "ALLOWEMPTYPASSWORD", value: "yes" },
{ name: "REDISPASSWORD", value: "examplepassword" }, { name: "REDISUSER", value: "default" }
]
})
}


brody
EMPLOYEE

a year ago

Don't think that is the correct format for the variables


brody
EMPLOYEE

a year ago

the CLI also can create databases -


tedimcboy
PROOP

a year ago

yeahhh im not exactly seeing what i need to make those queries work form what i've got. im totally lost even after looking at the docs, not getting anything useful back from the api really either (always just problem processing request). Do you know if im at least on the right track or if you could fix my query?


tedimcboy
PROOP

a year ago

all i can tell is that its possible but not seeing how to do it


brody
EMPLOYEE

a year ago

maybe it would be easier to just wrap the CLI?


tedimcboy
PROOP

a year ago

trying to wrap cli but doesn't let me link tio the project since its an interactive terminal. tried emulating but no luck


tedimcboy
PROOP

a year ago

using cli works great for creating redis and postgres services but to do that need to link the project id


brody
EMPLOYEE

a year ago

you can use link in a non-interactive way


brody
EMPLOYEE

a year ago

specify all the needed flags


brody
EMPLOYEE

a year ago

same for the add command, they both support non interactive modes


tedimcboy
PROOP

a year ago

master, slave = pty.openpty()
process = subprocess.Popen(
["railway", "link", "--project", projectid], stdin=slave, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, closefds=True
)
os.close(slave)

this does appear to work but requires a login. tried this as well to just pass my api key in but it still tells me to login:

    os.environ["RAILWAY_TOKEN"] = "API_TOKEN"

    result = [subprocess.run](subprocess.run)(
        ["railway", "link", "--project", project_id],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        text=True
    )

tedimcboy
PROOP

a year ago

guessing i can't do the login option through wrapping cli

just getting this:

Linking Railway CLI to project: 8e6ed70e-9dc8-4fdf-b2bf-b52f1f9d7153…
Failed to link to project 8e6ed70e-9dc8-4fdf-b2bf-b52f1f9d7153.
Error: Unauthorized. Please login with railway login

Process finished with exit code 0


tedimcboy
PROOP

a year ago

i have confirmed my api key functions properly as well


tedimcboy
PROOP

a year ago

sorry to ask so many quesitons, this is the last last thing


brody
EMPLOYEE

a year ago

os.environ doesn't set system environment variables, you'd need to pass the variable into the subprocess


tedimcboy
PROOP

a year ago

passed it directly into subprocess and its stil telling me to login. cli is very easy to use but i have no clue why using it in code is so dificult. do you happen to have a function anywhere that handles linking with the api key?tried this like 5 different ways just to link to the project and it tells me to login even though i passed the api key in directly


tedimcboy
PROOP

a year ago

creating the services is obviouslly a piece of cake through cli and even through wrapping it in code but linking it refuses to work. i can't find any docs showing a simple quick start example of wrapping the cli and my other methods are not seeming to work. such a simple thing too so a bit frustrating. once this is good i don't need to touch any of this code or mess with the api anymore at least (with the exception of generating a domain for the github service but i hope that should be simple)


brody
EMPLOYEE

a year ago

I think you want RAILWAY_API_TOKEN


tedimcboy
PROOP

a year ago

yeah man this isn't making any sense. im using RAILWAYAPITOKEN but it still doesn't work. i can create the project fine, link the repo, deploy the service, but for some magical reason i can't pass in the api key to bypass.

went back to the drawing board and ran: link with project, team, and environment flags but it saus input device is not a TTY


tedimcboy
PROOP

a year ago

i think i got it


brody
EMPLOYEE

a year ago

well at least you arent getting told you arent logged in


tedimcboy
PROOP

a year ago

sec


tedimcboy
PROOP

a year ago

progress is progress


tedimcboy
PROOP

a year ago

i got it! finally lol


brody
EMPLOYEE

a year ago

awesome!!


tedimcboy
PROOP

a year ago

i still need to generate the domain for the deployment which i think should be relatively easy? (might have jinxed it) but thanks so much for steering me in the right direction!


brody
EMPLOYEE

a year ago

the CLI can do that too


tedimcboy
PROOP

a year ago

sweet, gonna play wiht that now


tedimcboy
PROOP

a year ago

well almost everything is good but for whatver reason i can't fetch the postgres db url as it doesn't show up in railway variables. i see redis but when i run:

railway variables | grep "REDISPUBLICURL"

it just returns ║ REDISPUBLICURL │ redis:// ║

even though when i just run railway variables i can see the value for it.

and for postgres its just straight up not listed when i do railway variables


brody
EMPLOYEE

a year ago

try using the JSON output mode


tedimcboy
PROOP

a year ago

they are both being created and deploye properly through the cli but its a bit strange when trying to fetch values form them. tried using graphql but that only returns names, ids and such, not that actual values


tedimcboy
PROOP

a year ago

still no postgres db stuff in there even with json flag. kinda weird since i see it on the ui of the deployment


brody
EMPLOYEE

a year ago

did you link to postgres before asking for the postgres variables?


tedimcboy
PROOP

a year ago

ah would ya look at that


tedimcboy
PROOP

a year ago

thank you


brody
EMPLOYEE

a year ago

no problem


tedimcboy
PROOP

a year ago

one last question for you:

when running:
(.venv) tedrosmccoy@Tedross-MBP TalkTrain_API % railway link --project d8752a63-7cb2-452a-ba95-019e67db35cc --environment production --service redis

Select a team TalkTrain
Select a project panera-bread
Select an environment production
Select a service redis

Project panera-bread linked successfully! 🎉

in the cli it works perfectly, when running the exact same query in code through subprocess i get:

Adding redis service… Redis service added successfully. Linking to redis service… Error: Service "redis" not found.

the services are added perfectly with the add --database{databasetype} call, when i run {RAILWAYCLI} link --project {projectid} --environment {environmentname} --service {database_type}

that translates to** railway link --project d8752a63-7cb2-452a-ba95-019e67db35cc --environemnt production --service redis**

which is identical to the one that works through just the cli and not subprocess. does subprocess function differently?

`def addserviceandgeturl(projectid, environmentid, databasetype, variablename):

environment_name = "production"
RAILWAY_CLI = "railway"

print(f"\033[93mAdding {database_type} service...\033[0m")
# Step 1: Add the database service
add_command = f"{RAILWAY_CLI} add --database {database_type}"
add_result = run_cli_command(add_command)
if add_result is None:
    print(f"\033[91mFailed to add {database_type} service.\033[0m")
    return None
print(f"\033[92m{database_type.capitalize()} service added successfully.\033[0m")

# Step 2: Link to the newly created service using its exact name
service_name = database_type.capitalize()
print(f"\033[93mLinking to {database_type} service...\033[0m")
link_command = f"{RAILWAY_CLI} link --project {project_id} --environment {environment_name} --service {database_type}"
link_result = run_cli_command(link_command)
if link_result is not None:
    print(f"\033[92mLinked to {database_type} service successfully.\033[0m")
else:
    print(f"\033[91mFailed to link to {database_type} service.\033[0m")
    return None

# Step 3: Fetch environment variables in JSON format
print("\033[93mFetching environment variables...\033[0m")
variables_command = f"{RAILWAY_CLI} variables --json"
variables_result = run_cli_command(variables_command)

if variables_result:
    try:
        variables_json = json.loads(variables_result)
        # Step 4: Extract the required variable
        if variable_name in variables_json:
            value = variables_json[variable_name]
            print(f"\033[92m{variable_name}: {value}\033[0m")
            return value
        else:
            print(f"\033[91m{variable_name} not found.\033[0m")
            return None
    except json.JSONDecodeError:
        print("\033[91mFailed to parse variables JSON.\033[0m")
        return None
else:
    print("\033[91mFailed to fetch environment variables.\033[0m")
    return None`

brody
EMPLOYEE

a year ago

use the IDs not friendly names


tedimcboy
PROOP

a year ago

id for environment?


tedimcboy
PROOP

a year ago

ohhh the ids of the redis service


tedimcboy
PROOP

a year ago

and postgre


brody
EMPLOYEE

a year ago

Id for environment and service flags


brody
EMPLOYEE

a year ago

never use friendly names


tedimcboy
PROOP

a year ago

welp, passed in env id and fetched service id for both redis and postgres dynamically but it just says the service can't be found when running the link command. same exact command works perfectly through cli with both names and ids. through subprocess doesn't work with either of them despite other queries through subprocess working fine. I confirmed the project id, env id, and service ids were all correct after the query failed through code which makes no sense. the query structure is correct, im using only ids, api key is correct, and it works perfectly in just cli. this api is killin me man

printed out the query that is getting formed and run by code:

railway link --project d1317bbd-84e5-4271-8e93-19511e70815a --environment 5accb6f4-813b-46a2-9e7e-3dd17b37861c --service b09ae728-1b83-4ac0-adf3-1c29a46efd1d

which results in: Error: Service "b09ae728-1b83-4ac0-adf3-1c29a46efd1d" not found.

ran the exact same line in cli and i get:

**(.venv) tedrosmccoy@Tedross-MBP TalkTrain_API % railway link --project d1317bbd-84e5-4271-8e93-19511e70815a --environment 5accb6f4-813b-46a2-9e7e-3dd17b37861c --service b09ae728-1b83-4ac0-adf3-1c29a46efd1d

Select a team TalkTrain
Select a project panera-bread
Select an environment production
Select a service Postgres

Project panera-bread linked successfully! 🎉
**

am i crazy or does this not make sense


tedimcboy
PROOP

a year ago

its the exact same query, the other command through cli work fine so the api key is correct and linking does work. just for whatever reason it fails when done through code.
the line is link_command = f"railway link --project {project_id} --environment {environment_id} --service {service_id}"

and given the output is railway link --project d1317bbd-84e5-4271-8e93-19511e70815a --environment 5accb6f4-813b-46a2-9e7e-3dd17b37861c --service b09ae728-1b83-4ac0-adf3-1c29a46efd1d which works perfectly in just cli, think im either missing something obvious or this makes no sense

1318071961586368500
1318071961921781800


brody
EMPLOYEE

a year ago

i have to ask, what are you doing all this for?


tedimcboy
PROOP

a year ago

triggering a deployment on a form submission. someone submits a form, values are extracted, repo is forked, deployment is created and urls from the railway deployment are returned and inserted into the forked repo


tedimcboy
PROOP

a year ago

so far everything works except just linking to the specifc service to get those urls back but only in code. i understand things like the env may be handled differently through subprocess but this math is not mathing to me


brody
EMPLOYEE

a year ago

what is Panera Bread if i may ask


tedimcboy
PROOP

a year ago

just a sample company name that was submitted into the form lol


brody
EMPLOYEE

a year ago

haha yeah but what is it actually


tedimcboy
PROOP

a year ago

panera bread is a resturant chain if thats what you mean but that is the company name field exracted from the form just so i can track stuff


tedimcboy
PROOP

a year ago

they make some really top tier food but its so expensive


brody
EMPLOYEE

a year ago

what is the code doing, not the name lol


tedimcboy
PROOP

a year ago

code listens to a trigger from another code base, grabs the collection, extracts the name and some other info from it to create a deployment for said company. its effectively an api for automation, saves me time manually forking a repo, spinning up services on railway and plugging in the urls


brody
EMPLOYEE

a year ago

okay so why deploy a whole project for this? why not just make the app that you are deploying multi-tentant


tedimcboy
PROOP

a year ago

the forking, service deployment and all that is working great but this api really doesn't like me. im happy to share any code if you need more context


tedimcboy
PROOP

a year ago

its a bit complicated for how i ended up at this conclusion but having standalone deployments works best for this specific project. started off multi tennant but the nature of the companies using it kinda put me in a spot where i had to go stand alone


tedimcboy
PROOP

a year ago

this is the final final step, just getting the freakin redis and postgres urls back. should be doable but im prob just missing something simple. ik this sounds overly complex and all but there is some method to the madness and i'll be restructuring things later on


brody
EMPLOYEE

a year ago

okay ill have a think and get back to you


tedimcboy
PROOP

a year ago

guessing this is the scheduled maintinence but i think i figured out the issue. added a delay before linking and i guess maintinence was right when i was gonna test lol. when running the command through cli it didn't work for a second but running again it worked. this seems like the only logival solution to me so i'll test when everyhting is back online

1318083321904763000


tedimcboy
PROOP

a year ago

thanks for allt he help though man, i'll lyk if it works


brody
EMPLOYEE

a year ago

yeah thats the maintenance


brody
EMPLOYEE

a year ago

im gonna try to get you the query needed to deploy everything all at once with the api so you dont have to call to the cli and add sleeps, thats all too slow


brody
EMPLOYEE

a year ago

this should do what you want -
it requires you create a template for the services you want to deploy -

the code will -

  1. create a new project with a given name and description

  2. load the template

  3. show you how you could modify a service name or service repo on the fly

  4. deploy that template into the created project

1318104978027712500


brody
EMPLOYEE

a year ago

@Tedros ^ tag for viz 🙂


tedimcboy
PROOP

a year ago

dang man, you went above and beyond for my support request. really appreciate you!


brody
EMPLOYEE

a year ago

after I sent you on a wild goose chase trying to wrap the cli, I had to


brody
EMPLOYEE

a year ago

has it worked for you? do I need to modify or add anything?


tedimcboy
PROOP

a year ago

yep! everything is working perfectly


tedimcboy
PROOP

a year ago

thanks so much for the help man


tedimcboy
PROOP

a year ago

it does look like railway is down though


tedimcboy
PROOP

a year ago

as in just in the past few minutes, not sure if thats scheduled or not. just "no healthy upstream". anyways thanks again for bearing with me through that whole mess lol


medikornov
PRO

a year ago

same for me, railway is down


Hey sorry about that, this is due to an incident - https://status.railway.com/cm4rr5bzq001tz3e74khhwies

Could you confirm if things are back up for you?


brody
EMPLOYEE

a year ago

!s


Status changed to Solved brody about 1 year ago


Loading...