the class below should help, I have simplified token, end point and not attempted to create real data provider; you may add your parser and config reader but structurally, i hope you will see what you need to execute your call now:
<?php
namespace Mbs\GraphQL;
class SendToMonday
{
/**
* @var \Magento\Framework\Json\Helper\Data
*/
private $jsonHelper;
/**
* @var \Magento\Framework\HTTP\Client\Curl
*/
private $curl;
private static $endPoint = 'https://api.monday.com/v2'; // can be stored in config later
private static $token = 'AAAAAAAAAAAAAAAAAAAAAAAAAAA'; // can be stored in config later
public function __construct(
\Magento\Framework\Json\Helper\Data $jsonHelper,
\Magento\Framework\HTTP\Client\Curl $curl
) {
$this->jsonHelper = $jsonHelper;
$this->curl = $curl;
}
public function sendCallData()
{
$query = <<<MUTATION
create_item
(
board_id: "{$this->getBoardId()()}",
item_name: "{$this->getNewStatus()()}",,
column_values:
"{
\"text9\":\"Hello world\",
\"email\" :{\"email\":\"[email protected]\",\"text\":\"[email protected]\"},
\"dropdown\" :{\"ids\":[6,7,8,9]},
\"numbers\":\"3\",
\"sales_associate\" :{\"ids\":[5]},
\"status\" :{\"label\":\"TEST\"}
}"
)
{
id
}
MUTATION;
$this->postQuery($query);
}
private function postQuery(string $query)
{
$data = $this->jsonHelper->jsonEncode(['query' => $query, 'variables' => []]);
$this->curl->addHeader("Content-Type", "application/json");
$this->curl->addHeader("Content-Length", strlen($data));
$this->curl->addHeader('Authorization', 'Bearer ' . self::$token);
$this->curl->post(self::$endPoint, $data);
$result = $this->curl->getBody();
if (!empty($result)) {
$result = $this->jsonHelper->jsonDecode($result);
if (isset($result['errors'])) {
// error wrapping
}
}
}
}