0

我检查了 API 文档,但没有与 curl php 相关的示例。

我可以获得一些关于如何与 monday.com 连接以使用 curl php 在 monday.com 中创建潜在客户或交易的指南吗?

我有示例代码(此代码段中的令牌错误),但我不知道如何传递数据来创建潜在客户

<?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);
?>
4

1 回答 1

0

我不熟悉这个monday.com页面,但这是您可以在 PHP 中发出 cURL 请求的方法:

<?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);
于 2021-11-11T14:40:06.790 回答