3 months ago
My Goal:
Fetch logs via the Railway Public GraphQL API from Project A, but I can’t even retrieve the environmentId using a Project Token.
My Problem: I am using a Windows machine (yeah sry D:) and I tried to test the API in any way with curl and stuff. And ChatGPT wasn't helpful too…
I either get an error because the command is not working on windows or I get something like this:
{@{message=Project Token not found; locations=System.Object[]; path=System.Object[]; extensions=; traceId=2917802231414876688}}
And I am very sure that I copied the project token correctly!
This is one example I tested:
$TOKEN = 'YOURPROJECTTOKEN'
$ENDPOINT = 'https://backboard.railway.com/graphql/v2'
JSON-Body als Here-String (vermeidet alle Quote-Probleme)
$BODY = @'
{"query":"query { projectToken { projectId environmentId } }"}
'@
Invoke-RestMethod -Method POST -Uri $ENDPOINT -Headers @{ 'Project-Access-Token' = $TOKEN }
-ContentType 'application/json' `
-Body $BODY
Sry I am new to this type of api. In general I learned how to use REST APIs 1 month ago. So I hope you guys are not mad D:
10 Replies
3 months ago
Hey there!
The railway docs show off some intricacy that comes with the grapql endpoints! https://docs.railway.com/reference/public-api
From what I gather, I havent personally used it, the project access token bearer is your bingo card. It looks like you're running into a user key vs project key mismatch which are a bit different.
Theres also the graphql playground which can let you test without needing to use your terminal!
https://railway.com/graphiql
3 months ago
You mentioned "Fetch logs via the Railway Public GraphQL API" - but I'm curious why you need to fetch them this way? Also, which language and/or GraphQL client are you using?
The docs say - "Project tokens are scoped to a specific environment within a project and can only be used to authenticate requests to that environment." - so you may need an Account token instead of a Project token?
Also read the auth docs carefully, for example { "Authorization": "Bearer <API_TOKEN_GOES_HERE>" } - the request header needs to be this structure, literally with the word Bearer in there (with a space after it, then your token goes after that).
I didn't rly use any GraphQL client. That's probably the issue here. I just tried to make a request with the powershell xD Just to test it and got lost in the process!
Thank you for your answer!
Something like a tutorial would be nice. A Youtube video or something. Would be easier for me to understand it.
3 months ago
Your best bet is using an official sdk
3 months ago
For a quick overview Fireship always has my back:
https://youtu.be/eIQh02xuVw4?si=WXcNqWUnUBpBcERh
I also watched this one and it explained things well enough
https://youtu.be/Zg4XIpnLWQg?si=ThYvn99lrHuM-qwR
Happy to point in the right directions if need me.
3 months ago
What language are you trying to do this in? When all is said and done
3 months ago
On that, I think that trying to understand it can help you figure out whether or not its ideal to use it.
I'm curious also as to the end goal of this too! Maybe theres a different solution that works better
3 months ago
For anyone else interested, ended up finding a solution for this over DMs with Ego!
(There was some info about the project he didn't want public)
Instead of trying to find an endpoint with graphql and hit it each time another service wanted the logs, we ended with a structured json file for logs.
So say you have a file thats: 9-3-25.json you can define a helper function called log(level, message) something like that.
In that function, it both prints to console & appends to the end of the json file marked of todays date. (with extra logic for matching/creating if not exists and whatnot)
You can also set a check that if the file goes over ~5mb or something you create a new one or just start again. Keep up to 3-5 days worth of logs and can filter to only return N count of items in the array on an authorized rest endpoint for speed.
Customizable solution that is simple for this use case.
Status changed to Solved noahd • 3 months ago
3 months ago
!s