0

I checked the API documentation but there are no examples related to curl php.

Can i get some guide on how to connect with monday.com to create lead or deal in monday.com using curl php?

I have sample code (Token is wrong in this code snippet), but I have no idea on how to pass data to create lead

<?php
    $token = 'eyJhbGciOiJIUzI1NiJ9.0Y-0OesftWBt2SamhvuPV5MR-0Oq7iApMt2exFkDNdM';
    $apiUrl = 'https://api.monday.com/v2';
    $headers = ['Content-Type: application/json', 'Authorization: ' . $token];

    $query = '{ boards (limit:1) {id name} }';
    $data = @file_get_contents($apiUrl, false, stream_context_create([
      'http' => [
        'method' => 'POST',
        'header' => $headers,
        'content' => json_encode(['query' => $query]),
      ]
    ]));
    $responseContent = json_decode($data, true);

    echo json_encode($responseContent);
?>
  • `I have no idea on how to pass data`...so you mean your `$query` is just a guess, or what? Do you get an error or unexpected results when you run this code? Can you tell us the location of the documentation of the API, so we can check what it's expecting to receive – ADyson Nov 10 '21 at 10:02

1 Answers1

0

I'm not familiar with this monday.com page, but this is how you can make a cURL request in PHP:

<?php
$token = 'eyJhbGciOiJIUzI1NiJ9.0Y-0OesftWBt2SamhvuPV5MR-0Oq7iApMt2exFkDNdM';
$apiUrl = 'https://api.monday.com/v2';
$headers = ['Content-Type: application/json', 'Authorization: ' . $token];

//  Payload
$query = '{ boards (limit:1) {id name} }';
$payload = ['query' => $query];

//  Init cURL
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_URL, $apiUrl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

//  Exec cURL
$resp = curl_exec($curl);

//  Close cURL
curl_close($curl);

//  Get response
$response = @json_decode($resp, true);
Derenir
  • 537
  • 1
  • 12
  • 29
  • Thanks Derenir for sharing code but how to pass lead data in this code? – Momin Iqbal Nov 15 '21 at 06:20
  • The `CURLOPT_POSTFIELDS` option contains the payload of your request, you can pass any parameter through that array. Same goes for any header parameter in the `CURLOPT_HTTPHEADER`, for setting up the request header. For more info in your specific case, you sould refer to the [API's documentation](https://api.developer.monday.com/). – Derenir Nov 16 '21 at 07:27