That’s a great question! The issue is related to passing a string via cURL. Since you need to send your query as a JSON body, you will need to escape strings within the JSON so the server can read it correctly.
This should work for you. Notice the added backslashes before the Item Name value:
curl --location --request POST 'https://api.monday.com/v2' \
--header 'Authorization: XXXXXX' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"mutation { create_item (board_id: 1622487812, item_name: \"Look at me! I'\''m a ~Cool~ item from cURL\") { id } }"}'
@kolaai I’m afraid that in this case, the formatting is correct, as you are sending a JSON object.The “query” part of it is defining what you are sending to the server as an API query, although in other GraphQL implementations, this can use a different key.
I don’t know if it’s a windows thing but I have been trying the curl as you have suggested but it’s still failing on my side, can you please check my curl and correct me if I have done it wrong?
curl --location --request POST “https://api.monday.com/v2” --header “Authorization: XXXXXXXX” --header “Content-Type: application/json” --data-raw “{"query":"mutation { create_item (board_id: 1622487816,group_id: "emailed_items", item_name: "Test from Curl") { id } }"}”
It seems like you still need to add backslashes (making your " quotes look like \" instead) to the strings within the mutation. Here’s how the formatting should work:
curl --location --request POST "https://api.monday.com/v2" --header "Authorization: XXXXXXXX" --header "Content-Type: application/json" --data-raw "{"query":"mutation { create_item (board_id: 1622487816,group_id:\"emailed_items\", item_name: \"Test from Curl\") { id } }"}"
Can you let me know if that does the trick for you?
In your second example, you’ve added backslashes around each quote. You only need those around the strings that are inside the JSON body of your mutation. This query will not work:
"{\"query\":\"mutation { create_item (board_id: 1622487816,group_id:\"emailed_items\", item_name: \"Test from Curl\") { id } }\"}"