Skip to main content

PHP and the new Updated API

  • January 9, 2024
  • 4 replies
  • 441 views

I’m trying to make sure our website forms that submit data, information requests to our Monday boards are updated. Is this PHP tutorial page up to date? It doesn’t seem like it is.

https://support.monday.com/hc/en-us/articles/360013465659-API-Quickstart-Tutorial-PHP.

I’m trying to update the API headers and get an error in the code. What is the correct format? I’m trying

$headers = [‘Content-Type: application/json’, 'Authorization: ’ . $token, ‘API-version’ : 2024-01];

Thanks!

4 replies

  • Participating Frequently
  • January 9, 2024

I’d check the structure of the headers. There looks to be misplaced quotes, and the 2024-01 is a string value - so my instincts say it would be quoted would it not?


Matias.Monday
Forum|alt.badge.img
  • monday.com Team Member
  • January 10, 2024

Hello there @rcullen;

I also think the structure of the headers could be the issue here.

Here is an example I created using Postman:

<?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' => 'APITOKENHERE',
  'API-version' => '2024-01',
  'Content-Type' => 'application/json'
));
$request->setBody('{"query":"mutation {\\\\n  change_simple_column_value (item_id:9876543210, board_id:1234567890, column_id:\\\\"long_text\\\\", value: \\\\"Sample text\\\\") {\\\\n    id\\\\n  }\\\\n}","variables":{}}');
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();
}

  • Author
  • New Participant
  • January 16, 2024

Thank you Matias, I will try this out.


Matias.Monday
Forum|alt.badge.img
  • monday.com Team Member
  • January 17, 2024

Happy to help @rcullen