Basic PHP API v2 Example

Hi Dipro, thank you for your help.
i understand now where my mistake is: I put my variables in wrong place.
Cheers,
Alex

1 Like

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([ 'http' => [ 'method' => 'POST', 'header' => $headers, 'content' => json_encode(['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 :slight_smile: 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:[MYToken]’, '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… :crystal_ball:

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!

Thank you for the suggestion.
I removed that header and changed the authentication type to “API Key”.

But I still make it to the “ELSE” portion below:

if(res.indexOf(‘Account.Name’) > 0){
auth.authenticationSuccess();
} else {
auth.authenticationFailed(‘user/password incorrect’);
}

I am attempting to contact DOMO too, but their third party connector person must be out for the holidays.

Thanks!

Do let us know what Domo says! Happy to help further once you hear from them.

It turns out that the connection was successful - but my code for checking the return value was incorrect.
Since this is an API connection there is no username/password sent.

So when I check this:

if(res.indexOf(‘Account.Name’) > 0)

it will always return zero.

Instead, I need to check this:

httprequest.getStatusCode() == 200)

Now I just need to figure out how to write my query.

This works in the Monday developer site:

query {
boards () {
name
state
board_folder_id
owner {
id
name
}
}
}

But the DOMO Connector Builder does not like the format.

Thanks!

I made some progress but I have another question.
When I want to loop thru all of the Boards, I have a ‘for next’ loop with the upper limit of ‘Boards.Length’

I also need to grab all of the Items and Groups - but they don’t have that ‘Length’ property (or a count)

Do you have any documentation I can look at to figure that out?

I was looking here: https://monday.com/developers/v2#queries-section

But that does not even show the Boards.Length (even though I am currently using it!)

Thanks!

I’m a little new to API and Monday.com as well. I am building an Administrative Dashboard for my employees and we use Monday.com heavily for our Project & Estimation Planning and Tracking. I would like to create a table view of the Projects I have listed in a board on Monday.com to a back-end dashboard.

I currently use the following coding languages and infrastructures:
PHP 7.3
Codeigniter 3.10
CI Bonfire 1.8

At this time, I am simply trying to figure out how to display all information for each item in a row (using PHP) to create a table view for my technicians in their Admin Dashboard of my website.

Can someone assist me with the proper query? I’ve tested multiple ways in the Try It Yourself Section to no avail.

@tburks2392

I use the following which will produce an array for you to do whatever you see fit:

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

$query = 'query {
boards (ids: NUMERICBOARDID) {
groups (ids: group_title) {
    items {
      id
      name
      column_values {
        id
        text
        title
      }
    }
  }
}
}';
$headers = ['Content-Type: application/json', 'User-Agent: [MYTEAM] 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);

If you just want the whole board and don’t care about a specific group use the following query:

query {
boards (ids: 007007007) {
    items {
      id
      name
      column_values {
        id
        text
        title
      }
    }
  }
}

Hey y’all, we just released a PHP API quickstart! It will go through making API calls as well as a little bit about our GraphQL schema :slight_smile:

Here it is: PHP Quickstart

1 Like

Hi, I am very new to the API implementation and sorry for my poor english.
I copy the code of PHP Quickstart - Making your first API call and replace with my own API v2 Token , however it returns “null” value.
I not sure which part is wrong ,please help me. :persevere:

Hi @sim,

Have you copied the first example from the link?

Which environment are you using to make the API call?

Are you able to share some screenshots with us?

Hi @mitchell.hudson, basically I just copied the example and replace it with API v2 Token copied from Admin panel.

I test run the code on localhost and this it the output :
image

In addition, i copied the API v2 token and tried it on Developers tools, it shows “Internal server error” .

Remove the @ before file_get_contents function.
That prevents any error from showing.
You should be able to see what’s wrong.

1 Like

Hi @sim,

It looks like your query is incorrect.

It looks like you are missing the ‘boards’ keyword in the query before you provide the variables to the function.

If you restructure your query to be the below:
$query = '{ boards(ids: [1,2,3,], limit:100) { name id items { name column_values{id type text } } } }';
You should have a valid query.

You can test this in GraphiQL.

One other note that I will make, you probably is that if you are submitting the ids variable, you probably don’t need the limit variable as well given this will restrict the number of responses anyway

1 Like

Hi @rob and @mitchell.hudson , after remove the @ , the error message is “SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed”
It turns out that the I did not add CA certs into my php.ini file and the problem is solved.
You saved my days, thank you very much . :smiley: :smiley:

1 Like