Issues trying to use Railway Public API
brunoziie
PROOP

6 months ago

Hi,

I am trying to create a "PR Environments SaaS" using Railway to solve a internal demand of the company I work, and I am struggling with some issues related with services creation/managing using the public API.

These are the problems I am facing:

  • When I using the serviceCreate mutation, I can define variables to the service and it causes a double deploy instead of a single one. Using the Railway dashboard I can create a service without trigger a immediate deployment. I can't replicate this behavior using the API. I want to set all my configs (env vars, limits, sleeping, start command...) and then deploy. Is it possible?

  • When I create a variable referring to a variable from other service, the UI shows me the arrows linking both services, but when I go to variable list and try to get the value its shows <empty string>(at the Raw Editor its shown) First I think its caused the referred service being not ready, but this happens till for old services. If I go to UI, edit and put de same value (as in raw editor) and deploy, it's works. Currently I am using the environmentPatchCommit mutation. Ex: ${{mysql.MYSQL_URL}} (it's not specifically with mysql service, it happens with any referred services ).

What I am trying to achieve:

  • Create some databases (when needed);

  • Create application services (api, frontends...);

  • Set all needed variable for each service, referring to other services (when needed);

  • Add sleeping configs and add resource limits;

  • Avoid unnecessary deployments while I set everything up.

Solved

5 Replies

Railway
BOT

6 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!


brody
EMPLOYEE

6 months ago

Hello,

I think what would help here would be to open your networking tools, do the desired tasks you want to achieve with the dashboard, and then simply replicate the network calls the dashboard made in your code.

Best,
Brody


Status changed to Awaiting User Response Railway 6 months ago


brunoziie
PROOP

6 months ago

Hello, brody.

I already tried that, I'm not sure if the public API has the same endpoints of the frontend. I literally copied the content from my network tab, and when I try to run I got a 400 error.

Here a example:

const debug = async () => {
  const mutation1 = gql`
    mutation serviceCreate($input: ServiceCreateInput!) {
      serviceCreate(input: $input) {
        ...ServiceFields
      }
    }

    fragment ServiceFields on Service {
      id
      name
      icon
      templateServiceId
      createdAt
      projectId
      featureFlags
      templateThreadSlug
    }
  `;

  const mutation2 = gql`
    mutation stageEnvironmentChanges(
      $environmentId: String!
      $payload: EnvironmentConfig!
    ) {
      environmentStageChanges(environmentId: $environmentId, input: $payload) {
        id
      }
    }
  `;

  // this one works
  const res: any = await query(mutation1, {
    input: {
      projectId: "my_project_id",
      source: { repo: "oniryk-labs/http-ping" },
      branch: "main",
      environmentId: null,
      name: "http-ping-" + randomUUID().slice(0, 8),
    },
  });

  // this one fail with 400
  const res2 = await query(mutation2, {
    environmentId: "my_env_id",
    payload: {
      services: {
        [res.serviceCreate.id]: {
          isCreated: true,
          source: {
            branch: "main",
            repo: "oniryk-labs/http-ping",
          },
          deploy: {
            runtime: "V2",
          },
        },
      },
    },
  });
};

Do I missing somethig?


Status changed to Awaiting Railway Response Railway 6 months ago


brody
EMPLOYEE

6 months ago

The internal endpoint has different information you can mutate and different data that can be returned, you can use the internal endpoint with your API token, but that means we could introduce breaking changes at our discretion.


Status changed to Awaiting User Response Railway 6 months ago


brunoziie
PROOP

6 months ago

This is not ideal for me because of the possibility of breaking changes,

but I will try to do what I need using the internal API.

Thank you, brody.


Status changed to Awaiting Railway Response Railway 6 months ago


Status changed to Solved brunoziie 6 months ago


Loading...