Creating an item using an HTTP request

Hi I have this cURL request that I have been trying and failing to get it right, it gives me a 500 Error (Internal Error)

curl -X POST https://api.monday.com/v2 -H “Content-Type:application/json” -H “Authorization: XXXXXXXXXXXX” -d "{“query”:“mutation { “create_item” (“item_name”: “Testing from Curl”,“board_id”: 1622487812, “group_id”: “emailed_items”) { id }}” -v

I’m not sure why it won’t succeed because the GrahpQL query below works just fine:

mutation {
create_item (
board_id: 1622487812,
group_id: “emailed_items”,
item_name: “Testing from GraphQl”)
{ id }
}

Please help me and thanks in advance.

@kolaai Thanks, will go through the documentation again.

Hey @mxolisi

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 } }"}'

Here’s how it worked for me on my board:

@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 hope this helps!

-Alex

1 Like

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 } }”}”

Hey @mxolisi

Thank you for following up!

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?

-Alex

Hi @AlexSavchuk , thanks again for replying, I’m working on a windows machine and this

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 } }"}

does not work as I need to add backslashes as you have mentioned.

So after adding the backslashes it looks like this:

curl -X POST https://api.monday.com/v2 -H "Authorization: XXXXXX" -H "Content-Type: application/json" -d "{\"query\":\"mutation { create_item (board_id: 1622487816,group_id:\"emailed_items\", item_name: \"Test from Curl\") { id } }\"}" -v

When I submit it I get a 500 error

image

@mxolisi

Just to make sure we’re on the same page here, could you provide the error message you are seeing when sending the first request?

The formatting of JSON in cURL should be exactly the same as in Postman, when sending RAW data as JSON. Here’s an example:

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 } }\"}"

Sending the below should work:

"{"query":"mutation { create_item (board_id:1622487816, group_id:\"emailed_items\", item_name:\"Test from Curl\") { id}} "}"

Does that make sense? Let me know.

-Alex

1 Like

Hi @AlexSavchuk , Thanks, your solution worked on power automate but I’m still failing on windows CMD.

But I needed this for power automate, so thanks a lot, I will come and update after finding a solution for CMD.

Update

Hi @AlexSavchuk
Here is a curl that worked on my side:

curl -X POST "https://api.monday.com/v2" -H “Authorization: XXXXXX” -H “Content-Type: application/json” -d “{“query”: “mutation { create_item (board_id: 1622487816, group_id: \u0022emailed_items\u0022, item_name: \u0022new item\u0022) { id }}”}”

The quotations inside the mutation query were added as codes.

@mxolisi

Wow, thanks so much for sharing! I’ve never seen the quotes to be this kind of an issue, but your solution does make sense.

Thanks so much for sharing your findings with us, that’s definitely something to keep in mind.

-Alex

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.