1

I need to send some order information to monday.com using graphql

when order place I want to pass the data to monday.com graphql API

how can i send API request using graphql to monday.com

UPDATE

Endpoint :- https://api.monday.com/v2

Headers :

Authorization - AAAAAAAAAAAAAAAAAAAAAAAAAAA

Content-Type - application/json

mutation 
{
    create_item 
    (
        board_id: 0000000001,
        item_name: "NEW",
        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
    }
}
3
  • do you have your call working on postman? if you do, you may post it here.. then, we can post a translated version on how it should look in Magento, would that help? Commented Jun 30, 2020 at 11:31
  • hello @HerveTribouilloy, i have updated the question plz check
    – Hiren
    Commented Jun 30, 2020 at 11:56
  • Has the asnwer below made your issue any better? Commented Jul 1, 2020 at 12:31

1 Answer 1

1

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
            }
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.