#Can't use Railway Public API with Project Token (projectToken null / Not Authorized)

10 messages · Page 1 of 1 (latest)

sterile turret
#

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 = 'YOUR_PROJECT_TOKEN'
$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:

winged fjordBOT
#

New reply sent from Help Station thread:

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

You're seeing this because this thread has been automatically linked to the Help Station thread.

Public API Reference | Railway Docs

Learn about the Railway GraphQL Public API.

Railway

A browser-based playground to help you test your queries against the Railway public API.

winged fjordBOT
#

New reply sent from Help Station thread:

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).

You're seeing this because this thread has been automatically linked to the Help Station thread.

sterile turret
#

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!

sterile turret
#

Something like a tutorial would be nice. A Youtube video or something. Would be easier for me to understand it.

winged fjordBOT
rain void
# sterile turret Something like a tutorial would be nice. A Youtube video or something. Would be ...

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.

What is GraphQL? Learn how it compares to REST and why developers love this query language for reading and mutating data in APIs https://fireship.io/tags/graphql

GraphQL API Docs https://graphql.org/
SpaceX GraphQL API https://api.spacex.land/graphql/

#dev#graphql #100SecondsOfCode

Install the quiz app 🤓

iOS https://itunes.apple.com/us/ap...

▶ Play video

In this brief video I will be explaining GraphQL for beginners.

Join our Discord: https://discord.gg/WE92Cqs6Vk

🚀 Learn ReactJS By Building 6 Projects: https://codedamn.com/learn/reactjs-projects
🐙 GraphQL Course: https://codedamn.com/learn/graphql-for-beginners
► Buy Crypto on Coinbase: coinbase-consumer.sjv.io/PedroTech

Social
▬...

▶ Play video
#

What language are you trying to do this in? When all is said and done

#

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

rain void
#

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.