R
Railway•7mo ago
eggsovereasy

Creating service using GraphQL API

I'm trying to create a service using the GraphQL API using the serviceCreate mutation, but have two problems 1. How do I send in variables? The doc comment in the GQL schema says "The ServiceVariables scalar type represents values as the TypeScript type: Record<string, string>. Example: "{ foo: 'bar', baz: 'qux' }". So I tried exactly that with this mutation:
mutation ($input: ServiceCreateInput!) {
serviceCreate(input: $input) {
id
}
}
mutation ($input: ServiceCreateInput!) {
serviceCreate(input: $input) {
id
}
}
and input
{
"input": {
"environmentId": "<<REDACTED>>",
"name": "Worker",
"projectId": "<<REDACTED>>",
"branch": "main",
"variables": "{ foo: 'bar', baz: 'qux' }",
"source": {
"repo": "https://github.com/<<REDACTED>>"
}
}
}
{
"input": {
"environmentId": "<<REDACTED>>",
"name": "Worker",
"projectId": "<<REDACTED>>",
"branch": "main",
"variables": "{ foo: 'bar', baz: 'qux' }",
"source": {
"repo": "https://github.com/<<REDACTED>>"
}
}
}
The service does get created, but the variables come in as:
0={
1=
2=f
3=o
4=o
5=:
6=
7='
8=b
9=a
10=r
11='
12=,
13=
14=b
15=a
16=z
17=:
18=
19='
20=q
21=u
22=x
23='
24=
25=}
0={
1=
2=f
3=o
4=o
5=:
6=
7='
8=b
9=a
10=r
11='
12=,
13=
14=b
15=a
16=z
17=:
18=
19='
20=q
21=u
22=x
23='
24=
25=}
2. My other issue, is that the service does not deploy after it is created. I found the mutation serviceInstanceRedeploy but that only seems to work for services that have already deployed before.
19 Replies
Percy
Percy•7mo ago
Project ID: fe10b4ee-a87a-4f4d-9d88-355cef99b1e1
eggsovereasy
eggsovereasy•7mo ago
fe10b4ee-a87a-4f4d-9d88-355cef99b1e1
Brody
Brody•7mo ago
1. dont quote the variables object. 2. dont add the source to the serviceCreate mutation, add the source to the service with serviceConnect this will then trigger a deploy from the newly added source.
eggsovereasy
eggsovereasy•7mo ago
i get back an error
{
"errors": [
{
"message": "Variable \"$input\" of required type \"ServiceCreateInput!\" was not provided.",
"locations": [
{
"line": 1,
"column": 11
}
],
"extensions": {
"code": "BAD_USER_INPUT"
}
}
]
}
{
"errors": [
{
"message": "Variable \"$input\" of required type \"ServiceCreateInput!\" was not provided.",
"locations": [
{
"line": 1,
"column": 11
}
],
"extensions": {
"code": "BAD_USER_INPUT"
}
}
]
}
nvm, I got it It still doesn't initiate a deploy though
Brody
Brody•7mo ago
updated my info, check again
eggsovereasy
eggsovereasy•7mo ago
Ok thanks i'll give that a swing I'm getting an error for 'not authrized' with connectService, using the same token i used to create the service
Brody
Brody•7mo ago
what kind of token are you using?
eggsovereasy
eggsovereasy•7mo ago
I created a team token on my account screen in the tokens section
Brody
Brody•7mo ago
is the service you are trying to do serviceConnect on in said team?
eggsovereasy
eggsovereasy•7mo ago
Yes
Brody
Brody•7mo ago
send your serviceConnect mutation please
eggsovereasy
eggsovereasy•7mo ago
mutation ($id: String!, $input: ServiceConnectInput!)
{
serviceConnect(id: $id, input: $input) {
id
name
}
}
mutation ($id: String!, $input: ServiceConnectInput!)
{
serviceConnect(id: $id, input: $input) {
id
name
}
}
Brody
Brody•7mo ago
with the variables too please
eggsovereasy
eggsovereasy•7mo ago
{
"id": "478d1f11-67a1-4157-a170-6865790fb7c8",
"input": {
"branch": "main",
"repo": "https://github.com/gsandf/ai-worker-scraper"
}
}
{
"id": "478d1f11-67a1-4157-a170-6865790fb7c8",
"input": {
"branch": "main",
"repo": "https://github.com/gsandf/ai-worker-scraper"
}
}
Brody
Brody•7mo ago
scraper 🫤 are you aware that running a scraper on railway is generally against railway's tos?
eggsovereasy
eggsovereasy•7mo ago
I was not, we will come up with a different solution then
Brody
Brody•7mo ago
ill still figure this out for you, just dont use it to deploy a scraper lol
eggsovereasy
eggsovereasy•7mo ago
Ok sounds good, thank you
Brody
Brody•7mo ago
best not to risk the ban you are getting not authorized because that repo is tied to your personal account, thus you need to use a personal token when making that api request railways dashboard uses the correct token automatically