我正在开发一个 Drupal 模块,以便在发布特定类型的 Drupal 节点时创建一个 Smartsheet。
工作表创建得很好,但没有使用我用 formId 变量指定的模板。
我究竟做错了什么?
谢谢
代码是:
<?php
function smartsheet_node_insert($node) {
if ($node->type == 'oa_space') {
// Initialize URL Variables
$baseURL = "https://api.smartsheet.com/1.1";
$sheetsURL = $baseURL ."/sheets/";
$columnURL = $baseURL. "/sheet/" . $node->nid . "/columns";
// Insert your Smartsheet API Token here
$accessToken = "[my api token]";
// Create Headers Array for Curl
$headers = array(
"Authorization: Bearer ". $accessToken,
"Content-Type: application/json"
);
// Create new sheet
$theSheet = array(
'name' => $node->title,
'fromId' => '[template id]',
);
$postfields = json_encode($theSheet);
// Connect to Smartsheet API
$curlSession = curl_init($sheetsURL);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curlSession, CURLOPT_POST, 1);
curl_setopt($curlSession, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
$createResponse = curl_exec($curlSession);
// Assign response to PHP object
$createObj = json_decode($createResponse);
if (curl_getinfo($curlSession, CURLINFO_HTTP_CODE) != 200) {
//if (curl_errno($curlSession)) {
drupal_set_message("Oh No! Could not create sheet " . $node->title . "because " . $createObj->message);
} else {
// Tell the user!
drupal_set_message("A Smartsheet has been created for the " . $node->title . " project");
// close curlSession
curl_close($curlSession);
}
}
}