cURL request with valid GraphQL query fails with "Problem processing request"

The following GraphQL query works as expected for me:
read -r -d '' QUERY << EOF
{
"query": "query variables { variables(projectId: \"XXX\", environmentId: \"XXX\", serviceId: \"XXX\")}"
}
EOF

curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $API_TOKEN" --data "$QUERY" $RAILWAY_API_ENDPOINT
read -r -d '' QUERY << EOF
{
"query": "query variables { variables(projectId: \"XXX\", environmentId: \"XXX\", serviceId: \"XXX\")}"
}
EOF

curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $API_TOKEN" --data "$QUERY" $RAILWAY_API_ENDPOINT
However, the following deployments query returns: {"errors":[{"message":"Problem processing request"}]}.
read -r -d '' QUERY << EOF
{
"query": "query deployments { deployments(first: 1, input: { projectId: \"XXX\", environmentId: \"XXX\", serviceId: \"XXX\" }) { edges { node { id, staticUrl }}}"
}
EOF

curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $API_TOKEN" --data "$QUERY" $RAILWAY_API_ENDPOINT
read -r -d '' QUERY << EOF
{
"query": "query deployments { deployments(first: 1, input: { projectId: \"XXX\", environmentId: \"XXX\", serviceId: \"XXX\" }) { edges { node { id, staticUrl }}}"
}
EOF

curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $API_TOKEN" --data "$QUERY" $RAILWAY_API_ENDPOINT
The deployments query matches an example from the docs. When I run the deployments query in the Railway GraphQL playground, it works as expected. In all three cases I've triple checked that I'm using the same auth token and project/environment/service IDs. What could cause the issue with my deployments query? Thanks in advance. ❤️
5 Replies
Percy
Percy7mo ago
Project ID: d1b29819-2b0d-48bd-a758-50cf03a97b82
peterhartree
peterhartree7mo ago
Project ID: d1b29819-2b0d-48bd-a758-50cf03a97b82
Brody
Brody7mo ago
I'm gonna guess that it's something to do with how you're piping the query into curl, have you tried passing the query in with the --data flag like the curl example shows? https://docs.railway.app/reference/public-api#authentication
peterhartree
peterhartree7mo ago
@Brody Thanks for the reply. I am using the --data flag in the example I gave above. But yes, I get the same "Problem processing request" error if I pass the query in like this: curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $API_TOKEN" --data '{"query": "query deployments { deployments(first: 1, input: { projectId: "XXX", environmentId: "XXX", serviceId: "XXX" }) { edges { node { id, staticUrl }}}"} I find it particularly strange that both of the following are true: 1. The first query in my OP, the variables query, works as expected. This suggests that the way I'm piping the query into the cURL request is ok. It also confirms that my project/service/environment IDs are valid. 2. The second query works as expected in the GraphQL playground (with the same project/service/environment IDs). This suggests that my query is valid. The only structural difference I can see between the two queries is the { edges { node { id, staticUrl }} part in the second query. But I can't see a formatting error there. Ohhh wow I'm sorry. There should have been four curly braces here staticUrl }}}, not three. 🤦‍♂️ @Brody Thank you again for your reply here. I had looked at this for an hour or so before resorting to Discord. Happy New Year.
Brody
Brody7mo ago
no worries, happy new year to you too, and for anyone in the future who may come across this thread, here is the complete query and variables
query deployments($first: Int, $input: DeploymentListInput!) {
deployments(first: $first, input: $input) {
edges {
node {
id,
staticUrl
}
}
}
}
query deployments($first: Int, $input: DeploymentListInput!) {
deployments(first: $first, input: $input) {
edges {
node {
id,
staticUrl
}
}
}
}
{
"first": 1,
"input": {
"projectId": "",
"environmentId": "",
"serviceId": ""
}
}
{
"first": 1,
"input": {
"projectId": "",
"environmentId": "",
"serviceId": ""
}
}