Skip to main content

I am attempting to follow the PHP tutorial located here:

Support

Just trying to find a way to add an item with column data via PHP,

Any help much apprecieated.

Hello @hderic!

I see you created a ticket with us about this.

I have replied over there 🙂

Cheers,
Matias


Thank you Matias! Got it to work using the PHP curl example you emailed me. I thought Id post the examples you sent here incase they can help the next person.

FYI I only tested the first one (PHP cUrl)

PHP - cURL:

<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.monday.com/v2',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{"query":"mutation ($myColumnValues: JSON!) { create_item ( board_id: 123456789, group_id: \\\\"topics\\\\", item_name: \\\\"My Item\\\\", column_values: $myColumnValues ) { id } }","variables":{"myColumnValues":"{\\\\"text\\\\":\\\\"Some text\\\\"}"}}',
CURLOPT_HTTPHEADER => array(
'Authorization: MYAPIKEYHERE',
'Content-Type: application/json',
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

PHP Guzzle:

<?php
$client = new Client();
$headers = [
'Authorization' => 'MYAPIKEYHERE',
'Content-Type' => 'application/json',
];
$body = '{"query":"mutation ($myColumnValues: JSON!) { create_item ( board_id: 123456789, group_id: \\\\"topics\\\\", item_name: \\\\"My Item\\\\", column_values: $myColumnValues ) { id } }","variables":{"myColumnValues":"{\\\\"text\\\\":\\\\"Some text\\\\"}"}}';
$request = new Request('POST', 'https://api.monday.com/v2', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();

PHP HTTP Request 2:

<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.monday.com/v2');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Authorization' => 'MYAPIKEYHERE',
'Content-Type' => 'application/json',
));
$request->setBody('{"query":"mutation ($myColumnValues: JSON!) { create_item ( board_id: 123456789, group_id: \\\\"topics\\\\", item_name: \\\\"My Item\\\\", column_values: $myColumnValues ) { id } }","variables":{"myColumnValues":"{\\\\"text\\\\":\\\\"Some text\\\\"}"}}');
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}

PHP pecl_HTTP:

<?php
$client = new http\\Client;
$request = new http\\Client\\Request;
$request->setRequestUrl('https://api.monday.com/v2');
$request->setRequestMethod('POST');
$body = new http\\Message\\Body;
$body->append('{"query":"mutation ($myColumnValues: JSON!) { create_item ( board_id: 1234567890, group_id: \\\\"topics\\\\", item_name: \\\\"My Item\\\\", column_values: $myColumnValues ) { id } }","variables":{"myColumnValues":"{\\\\"text\\\\":\\\\"Some text\\\\"}"}}');
$request->setBody($body);
$request->setOptions(array());
$request->setHeaders(array(
'Authorization' => 'MYAPIKEYHERE',
'Content-Type' => 'application/json',
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();

Thanks again!


Hello there @hderic,

Thank you for sharing this!!

Cheers,
Matias