Problems with java post response

Hi community! let’s see if you can solve my problems.
I’m trying to create a pulse with post http from java and i recieve that error message:
“No query string was present”

I’m sending a String :
String data = “‘mutation’ { ‘create_item’(board_id: xxx, group_id: ‘topics’, item_name: ‘Api created’) {id}}”;
And content type application/graphql

If anyone can help me please!
Thank you!

Any ideas on this? Unfortunately I’ve got the same problem trying to create a pulse in Monday.com

Using the Monday API tester (monday.com) it works. However, using scriptrunner in JIRA i can only get a successfull test using a “query” not a “mutation” request.

def msg = [
query: ‘{boards (ids: XXXX) {groups {id}}}’
] - WORKS

def msg = [
mutation: ‘{create_item (board_id: XXXX,group_id: “new_group”,item_name: “MyItem1”) {id}}’
] - FAILS WITH ERROR BELOW

Response:
“statusText”: “OK”,
“parsingError”: {
“present”: false
},
“body”: “{"errors":[{"message":"No query string was present"}],"account_id":XXXXXX}”,
“status”: 200,
“rawStatusCode”: 200

Any ideas why?

Mutations must be sent in POST

Cheers for the response, i did have it as a POST though:

post(‘https://api.monday.com/v2’)
.header(‘Content-Type’, ‘application/json’)
.header(‘Authorization’, “${apiToken}”)
.body(msg)
.asString()

possibly a ScriptRunner quirk, i’ve not used it before trying this?
(also tried application/graphql)

Make sure the content-type is correctly set as application/x-www-form-urlencoded.
See documentation at https://monday.com/developers/v2#introduction-section-how-to-get-started-using-the-api.
I suggest you to try a cURL command as in the example.

Same problem unfortunately. I’ve been through as much documentation as i can find. The API doc states the content-type should be application/json but i tried the other one anyway.

curl -X POST -H “Content-Type:application/x-www-form-urlencoded” -H “Authorization:xxxx” -d ‘{“mutation”:“{create_item (board_id: xxx,item_name: "my curl item") {id}}}”}’ “https://api.monday.com/v2/

same error - No query string was present.

Again, the “query” command works fine. Maybe it’s a Monday.com setting that I don’t know about, white-listed sources perhaps. I’m going to check that.

@simonWT It definitely works in my tests.



Please try the following cURL command.
curl -X POST -H 'Authorization:XXX' -H 'Content-Type: application/json' -d '{"query":"mutation{create_item(board_id:XXX,item_name:\"new item\"){id}}"}' 'https://api.monday.com/v2/'

Note that the mutation is wrapped inside a query container.

@dipro Regarding the problem experienced by @simonWT I noticed some confusion in the cURL example in your documentation at https://monday.com/developers/v2#introduction-section-how-to-get-started-using-the-api.
The problem is that while query command works both if wrapped or not inside another query property, mutation requires wrapping.

{"query":"query { ... }"}WORKS
{"query":"{ ... }"}WORKS
{"query":"mutation { ... }"}WORKS
{"mutation":"{ ... }"}DOESN’T WORKS

2 Likes

thanks @rob, that’s definitely where i was going wrong. Cheers!

Although the curl still has an issue with the JSON format for some reason.
However, i’m using an online version as i can’t use the one from my machine as my company proxy is twitchy about https://reqbin.com/

I’ve just tested it within Script Runner JIRA App and it’s worked. Now i’ll see about getting the dynamic elements in. Thanks again.

1 Like

Jumping in to clarify the behaviour that Rob mentioned:

First off, all operations to a GraphQL API are queries. Mutations are a subset that write or update data, but they are a kind of query.

All requests to our API should use the ‘query’ key to send the query string (which could read or mutate data). This is why option 4 doesn’t work – you need to pass the mutation as the “query” key.

If your query string doesn’t include the keyword “query” or “mutation” at the front then our query parser will assume it is a read operation.

This is why this works: {"query" : "{boards { id } }"}
But this does not: {"query" : "{create_item(...) {id}"}

Hope this helps clarify things. I’ll also see about adding this to the documentation somewhere.

2 Likes