Formatting GraphQL into JSON to send via API

I have been able to successfully us the “Try it Yourself” to create both query and mutation graphQL statements. Whenever I try to take these over to Postman and use the API, I contunually have issues…“query not found” Here is the latest:

Try it Yourself Request:
mutation {change_multiple_column_values(
board_id: 312587506, item_id: 544770494,
column_values: “{“date4”: {“date”:“2020-03-01”}}”
)
{
id
}
}

Try it Yourself Result:
{
“data”: {
“change_multiple_column_values”: {
“id”: “544770494”
}
},
“account_id”: 4567162
}

Postman request:
URL: https://api.monday.com/v2/
Methid: Post
Body:
{
“mutation”:"{change_multiple_column_values(board_id: 312587506, item_id: 544770494, column_values: {“date4”:{“date”:“2020-03-01”}}) { id } }"
}

Postman Reponse:
{
“errors”: [
{
“message”: “No query string was present”
}
],
“account_id”: 4567162
}

I have been able to get this to work with query instead of mutate, but at a loss why it does not recognize that there is graphQL string.

Hi @damercer6372. What body method in Postman are you using? Select the GraphQL option for the body, and you should literally be able to copy and paste your code from the “Try it Yourself” page.

Devin,

That is great to know. The end goal is to have this is a Node JS script that can make the API calls instead of Postman. Is there a way to wrap the graphQL into JSON and call the API. I have had success with this,

David

Yep! You basically just need to wrap the GraphQL query/mutation with JSON.stringify()

But you are going to like this…
In Postman, look over on the right side directly under the the “Save” button; there is a little “Code” button. Postman can generate the code for you in just about any possible “flavor” you need, including NodeJs! Enjoy. :grinning:

1 Like