Here’s a basic snippet of PHP that lets me execute queries against the v2 API and return the data as JSON. I hope it can provide a leg up and save someone time as they get started.
Just enter your own API key, change the URL to match yours, and put in your query.
thanks, I’ve tried to create a board with a group “test” that contains a simple title and a note column (type:text). I want to add an item with this query below.
It works, but it doesn’t add the value in the text column “note”. the column stays empty…
hey @thomasvandenbulcke,
first of all, lets make sure that you have the correct column id for the notes column.
you can try out this query via our GraphiQL try it yourself interface to see all columns of that board:
query{
boards (ids: xxxxxxxxx){
columns{
id
title
type
}
}
}
now that you are sure you have the correct column ID lets look at the mutation itself.
since the column values are a string inside a string they need to be escaped, like so: column_values: "{\"note\": \"a easy text here\"}"
I have used this Code to create a pulse/item and change columns values in a board. It works well. I am working on moving changing the code from the API v1 to API v2. In v1 when I create a new pulse/item in a group it places the new pulse/item at the top of the group.
I noticed with v2 it places the pulse/item at the bottom of the group. Is there anyway to make a new pulse/item go to the top like it does with v1?
Hey @renow,
Currently it is not possible to add a new item to the top of the group.
API v2 works similar to the way you add items in the monday platform using the “New” button or the empty item row marked “+Add”.
Hey @Ayelet
Thanks for the response. I have another question. How do I insert variables in this code? I would like to pass $_POST data from a web form to this code so it can dynamically add the value to the column with the variable $columnValue. How do I go about doing this?
You can dynamically update variables by including references to variables in your query and then passing the actual data for these variables in another “variables” JSON string in the request body. For example, this request would let you dynamically populate the board ID, item name, and columns in a mutation.
Query string (“query” value in request body)
mutation ($board: Int!, $name: String!, $column: JSON!) {
create_item( board_id: $board, item_name: $name, column_values:$column) {
id
column_values {
id
value
}
}
}
Hey @alextop – are you using “https://[whatpresents].monday.com/v2” as the URL, or is this dummy data? This is not a valid URL, I’d suggest using https://api.monday.com/v2
Are you receiving an error from our server? If you are, it indicates your query isn’t formatted correctly and I can help you figure out what the problem with it is.
If your code isn’t sending a request to our server at all, that means there’s an issue with your code (as opposed to the query). I’m not super familiar with PHP and can’t really help you debug syntax errors.
To figure out if the issue is with your query or the code itself, let’s try a simple query first (before moving to a mutation). Can you try the code below and let me know if it works?
Hi Dipro,
yes I have fixed , the reason was that I missed CURLOPT_HTTPHEADER information.
I have another question. When I create a new item and populate columns, I can fill the cells with Text type, but not with Long Text format. IDs of columns are correct (taken from query). Has someone complained on similar issue with Long Text format ?
mutation ($name: String!) {
create_item ( board_id: 201725833, group_id: “lost”,
item_name: $name,
column_values:
“{
“text7”:“NY” ,
“numbers60”:“2” ,
“delivery_address”:{“text”:“address text is here”} ,
“email”:{“email”:“test@test.com”,“text”:“test@test.com”}
}”
) { id } }
{
“name” : “new user”
}
Hello,
the code works fine with constant “item_name” (like: item_name: “superuser”. However, once i declare variable $name, (the code is above) i got parse error. What am I doing wrong with variables value, or something else ?