Skip to main content

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.


$token = ' Personal API Token]';
$tempUrl = "https://api.monday.com/v2/";

$query = ' {
users{
id
email
name
}
}';
$headers = ='Content-Type: application/json', 'User-Agent: :MYTEAM] GraphQL Client', 'Authorization: ' . $token];
$data = @file_get_contents($tempUrl, false, stream_context_create(e
'http' => ;
'method' => 'POST',
'header' => $headers,
'content' => json_encode(e'query' => $query]),
]
]));
$tempContents = json_decode($data, true);

Hey @jsachief – this is amazing!


Thanks for sharing 💯


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… 😦


$token = ‘ Personal API Token]’;

$tempUrl = “https://api.monday.com/v2/”;


$query = ’

mutation {

create_item (board_id: xxxxxxxxx, group_id: “test”, item_name: “new item”, column_values: “{"note": "a easy text here"}” ) {

id

}

}

';


$headers = r‘Content-Type: application/json’, ‘User-Agent: TMYTEAM] GraphQL Client’, 'Authorization: ’ . $token];

$data = @file_get_contents($tempUrl, false, stream_context_create(/

‘http’ => t

‘method’ => ‘POST’,

‘header’ => $headers,

‘content’ => json_encode(a‘query’ => $query]),

]

]));

$tempContents = json_decode($data, true);


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


let us know if it worked 🙂


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


i copied the code “as is” , only replaced token and MYTEAM text, but it does not work for me . I do not know where a mistake is


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?


$token = ‘Personal API Token]’;

$tempUrl = “https://api.monday.com/v2/”;


//Place a Web form Name field value into a variable to add to a monday.com column

$$columnValue = $_POST=‘name’];


$query = ’

mutation {

create_item (board_id: xxxxxxxxx, group_id: “test”, item_name: “new item”, column_values: “{“Name”: “$columnValue”}” ) {

id

}

}

';


$headers = <‘Content-Type: application/json’, ‘User-Agent: pMYTEAM] GraphQL Client’, 'Authorization: ’ . $token];

$data = @file_get_contents($tempUrl, false, stream_context_create(p

‘http’ => e

‘method’ => ‘POST’,

‘header’ => $headers,

‘content’ => json_encode(e‘query’ => $query]),

]

]));

$tempContents = json_decode($data, true);


Hey @renow!


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

Variables (“variables” value in request body)


{"board": 139415582, 
"name": "Hello world",
"column" : "{\\"status\\" : {\\"index\\" : 5}}"
}

For more context, the GraphQL website has a great introduction to this: https://graphql.org/learn/queries/#variables


Alex, what error are you receiving?


Hi Dipro, thanks for coming back . I am new in php and have a feeling that have made some basic mistake, here is my code:


<?php

$token = '[ here is my token ]';
$tempUrl = 'https://api.monday.com/v2/';

$query='
mutation {
create_item (board_id: 231718005, item_name: "new ABC customer", column_values: "{\\"note\\": \\"test text \\"}" )
{ id
}
}
'
;

$headers = ['Content-Type: application/json', 'User-Agent: [whatpresents] GraphQL Client', 'Authorization:' . $token];

$data = @file_get_contents($tempUrl, false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => $headers,
'content' => json_encode(['query' => $query]),
]
]));
$tempContents = json_decode($data, true);

?>

mutation snippet works fine through “…/v2/try-it-yourself” page.


Hey @alextop – are you using “https://swhatpresents].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 🙂


thanks !

i have replaced the url but is is something else (


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?



Ah @alextop – did you fix your code, as per this message?


Can you tell me what was wrong?


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 ?


Oh nice!


The long text column has a different structure as the text column – check our documentation at developers.monday.com for a full example.


Cheers!

Dipro


hi Dipro,

i have found and fixed. Thanks a lot for your support !

Cheers,

Alex


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 ?


Hey Alex! The query structure looks correct. Are you sending the variables as a variables value in your HTTP request?


Your request’s body should look like this:

{ “query” : your query here],

“variables” : byour variables here] }


Hi Dipro, thank you for your help.

i understand now where my mistake is: I put my variables in wrong place.

Cheers,

Alex


Hi,


I am trying to create a page that would insert a new pulse on one of our boards. The above threads really helped and I was able to create a pulse with one column, however, when I am trying to insert data in each column I am getting a Parse error on " : " (STRING).


This is what I’m trying to run:


<?php
$token = ' MY TOKEN]';
$tempUrl = "https://api.monday.com/v2/";

$name = "John";
$trainer = "Jeff";

$query = ' mutation{
create_item(board_id: xxxxxxx, group_id: "Active", item_name: "' . $name . '", column_values: "{"Trainer" : "' . $trainer . '", "Location" : "London", "Course" : "After Effects"}"){
id

}
}
';
$headers = ='Content-Type: application/json', 'User-Agent: :MY TEAM] GraphQL Client', 'Authorization: ' . $token];
$data = @file_get_contents($tempUrl, false, stream_context_create(e
'http' => ;
'method' => 'POST',
'header' => $headers,
'content' => json_encode(e'query' => $query]),
]
]));
$tempContents = json_decode($data, true);

print_r($tempContents);

?>

Appreciate any help I can get guys !!


Thanks,


Hey @Stephen, sorry for the late response here we just saw this.


Were you able to get your code working?


I suspect the issue here is that you are sending strings inside the JSON string without escaping them. I would suggest sending the column values in a format like so: column_values : "{\\"text\\" : \\"hello world\\"}"


Let me know if that works.


Hi @dipro,


Yes, we were able to get it to work 🙂 Thanks for the follow up, I appreciate it.


Newbie here! I want to use basically this same HEADER you have to create an API Connector in DOMO. But my authentication fails, even though I know the username and password is correct.


my code looks like this: (encodedData is the actual username and password)


httprequest.addHeader(‘User-Agent: :MYTEAM] GraphQL Client’, ‘Authorization:aMYToken]’, 'Basic ’ + encodedData);

var res = httprequest.get(‘https://(MYTEAM].monday.com/v2/’);


I tried with and without including the “Content Type” parameter.

What is the best way of seeing where I am going wrong? I have zero API experience and any suggestions would be appreciated. Thanks!


Hey John!


I see a couple of problems in your code.



Authentication


Our API uses token-based auth, which is slightly different from Basic auth. Looks like you’re using both in your code… 🔮


I’d suggest removing that third header (Basic + encodedData) because Basic not needed to access our API.



Request Format and Verb


All requests to our API should be POST requests, with a “query” parameter sent in the body. Check out this article for a quick introduction: https://support.monday.com/hc/en-us/articles/360005144659-Does-monday-com-have-an-API-?abcb=8536


Let me know if that helps!