Newbie pulling out hair - No query string was present

I’ve been working with Monday for about a week now, and I swear this exact code was working a few days ago. But now the response I get is “No query string was present”. I checked and rechecked the api key, board id, column ids, etc.

   $headers = [
        "Content-Type: application/json",
        "Authorization: $apiKey",
        "API-Version: 2023-10" //brand new as of January 2024
    ];

    $url = "https://api.monday.com/v2";
    $method = "POST";
    $boardID = $boardID;
    $query = 'mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id: ' . $boardID  . ', item_name:$myItemName, column_values:$columnVals) { id } }';

    $vars = ['myItemName' => "JOHN DOE",
             'columnVals' => json_encode([
             'contact_phone' => $phone,
             'countryShortName' => 'US', //an attempt to get the US flag to show up
             'text0' => "#DA"
        ])];

    $ch = curl_init();

    $je = json_encode(['query' => $query, 'variables' => $vars]);
    $jd = json_decode($je);

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $je);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);

Any assistance would be GREATLY appreciated.

The short answer is “I don’t know”, but I’ve cleaned up the code so that it is a bit more readable and only has what’s needed there:

<?php
$apiKey = "************"; // this is a secret
$boardID = "123456"; // some board ID

$headers = [
  "Content-Type: application/json",
  "Authorization: $apiKey",
  "API-Version: 2023-10" // brand new as of January 2024
];

$query = '
  mutation ($myItemName: String!, $columnVals: JSON!) { 
    create_item (
      board_id: ' . $boardID  . ', 
      item_name: $myItemName, 
      column_values: $columnVals
    ) 
	{ 
      id 
    } 
  }
';

$vars = [
  'myItemName' => "JOHN DOE",
  'columnVals' => json_encode([
    'contact_phone' => $phone,
    'countryShortName' => 'US', //an attempt to get the US flag to show up
    'text0' => "#DA"
  ])
];

$ch = curl_init();

$payload = json_encode([
  'query' => $query, 
  'variables' => $vars
]);

curl_setopt($ch, CURLOPT_URL, "https://api.monday.com/v2");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);


Thank you David. I was just going by the examples I came across.

Figured it out. Silly issue. The APIkey was read from a database and it had a line feed at the end of it. Message threw me off.

Thanks David. I amusing your code structure.

3 Likes

amusing or am using? :joy:

2 Likes

Thank you @dvdsmpsn for the help!

Cheers,
Matias

Thank you for the help

pulling out A hair ties (also called a ponytail holder, hair band, hair elastic, wrap around, gogo, or bobble) is an item used to fasten hair, particularly long hair, away from areas such as the face.