How do I create new environment via CLI?
devilirika
PROOP

7 months ago

I'd like to create new environment via CLI and I'm having issues with authentication.

If I use existing project token that is scoped to a staging environment, I can't create new environment as I get an error
```

Failed to get environments: Not Authorized: {"response":{"errors":[{"message":"Not Authorized","locations":[{"line":2,"column":3}],"path":["environments"],"extensions":{"code":"INTERNAL_SERVER_ERROR"},"traceId":"5831592547172749352"}],"data":null,"status":200,"headers":{}},"request":{"query":"query GetEnvironments($projectId: String!) {\n environments(projectId: $projectId) {\n edges {\n node {\n id\n name\n deployments {\n edges {\n node {\n id\n status\n }\n }\n }\n serviceInstances {\n edges {\n node {\n id\n domains {\n serviceDomains {\n domain\n id\n }\n }\n serviceId\n }\n }\n }\n }\n }\n }\n}","variables":{"projectId":"53e4391c-546e-4e1f-89ec-0c07af6f0fa4"}}}
```

If I use account token scoped to the team, I get error Project Token not found

If I login to Railway CLI via railway login, I can create new environment but that flow isn't an option since we are going to be creating new environments in scripted environment (in CI pipeline). We need ability to use RAILWAY_TOKEN= variable.

Solved

4 Replies

Railway
BOT

7 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


7 months ago

Hello,

You need to use an account token with the correct environment variable set, and make sure it is the only token variable set.

https://docs.railway.com/guides/cli#account-tokens

Best,
Brody


Status changed to Awaiting User Response Railway 7 months ago


devilirika
PROOP

7 months ago

I must be doing something wrong but I can't find the mistake. I created 2 tokens on https://railway.com/account/tokens, one with "No workspace selected" in the Team dropdown (that token's called personal token, right?) and one with our workspace selected in the Team dropdown. None of them work if I run command `RAILWAY_TOKEN=<full token redacted> railway environment new -d staging pr-33`, I get "Project Token not found" error for both tokens.


Status changed to Awaiting Railway Response Railway 7 months ago


7 months ago

The project-level RAILWAY_TOKEN cannot create environments, as it's scoped to a single environment.

If both tokens are set, as they are in your case, the RAILWAY_TOKEN will take precedence. So you will likely want to remove your project-level token.

Read more about tokens and the CLI in the CLI Docs.


Status changed to Awaiting User Response Railway 7 months ago


Railway
BOT

6 months ago

This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!

Status changed to Solved Railway 6 months ago


Loading...