2017-02-08 36 views
0

我發現這段代碼更新SmartSheet website中的單元格。但我不明白字段變量中的值是什麼。有沒有人有PHP代碼的工作例子來做到這一點?使用PHP腳本更新Cell SmartSheet 2.0

curl https://api.smartsheet.com/2.0/sheets/{sheetId}/rows?include=objectValue \ 
-H "Authorization: Bearer ACCESS_TOKEN" \ 
-H "Content-Type: application/json" \ 
-X PUT \ 
-d '[{"id": "6572427401553796", "cells": [{"columnId": 7518312134403972,"objectValue": {"objectType": "PREDECESSOR_LIST","predecessors": [{"rowId": 567735454328708,"type": "FS","lag": {"objectType": "DURATION","days": 2,"hours": 4}}]}}]}]' 

我當前的PHP代碼是如下,我只是想更新某個值到sheet.I不知道要放什麼東西在場上varaible。謝謝。

<?php 

$baseURL = "https://api.smartsheet.com/2.0"; 
$getSheetURL = $baseURL. "/sheets/4925037959505xxx/rows?include=objectValue"; 
$accessToken = "34ouqtkxp0sutdv6tjbwtsxxxx"; 

$headers = array("Authorization: Bearer ". $accessToken , "Content-Type: application/json"); 


$fields='[????]'; 

$ch = curl_init($getSheetURL); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); 
$result = curl_exec($ch); 
print_r($result); 
?> 

由於

回答

0

這是我創建更新SmartSheet

  • $ SSID的功能:是智能表ID
  • $ ssRowID:是智能錶行ID我 要更新
  • $值:在列的值的數組
  • $ columArray:是 列編號
  • $配置的陣列:是一個數組,我用它來保存所有 Informa的權威性重刑

打破JSON數據是你溝通,你要更新的列的方式和價值觀

  • { 「ID」: 「 '$ ssRowID'」,

    • 「細胞」:

    • [

    • {「columnId」:'。$ columnArray ['go']。',「value」:「'。$ values ['go']。'」},
    • {「columnId」:'。$ columnArray [ ''comment']。','value':''。$ values ['comment']。'「},
    • {」columnId「:'。$ columnArray ['data center']。',」value「 :「'。$ values ['datacenter']。「「}
    • ]
  • }

  • ID代表要更新

  • ColumnID的代表要更新必須提供列ID和值每列該行表示值要插入

{ 「ColumnID的」: '在這裏你列ID', 「值」: '你的價值在這裏'}

function ssUpdate($ssID, $ssRowID, $values, $columnArray, $config){ 


    /* 
    * update the Smart Sheet using the passed in sheet ID, Row ID and VALUES 
    * 
    */ 

    $sheetID = $ssID; 
    $SSAPIToken = $config['smartsheets']['SSAPIToken']; 
    $sheetsURL = "https://api.smartsheet.com/2.0/sheets/".$sheetID."/rows"; 
    $data_json = '[{"id": "'.$ssRowID.'", "cells": [{"columnId": '.$columnArray['go'].',"value": "'.$values['go'].'"}, {"columnId": '.$columnArray['comments'].',"value": "'.$values['comment'].'"}, {"columnId": '.$columnArray['data center'].',"value": "'.$values['datacenter'].'"}]}]'; 

    //echo $data_json."<br />"; 

    // Create Headers Array for Curl 
    $headers = array(
     "Authorization: Bearer " .$SSAPIToken, 
     'Content-Type: application/json', 
     'Content-Length: ' . strlen($data_json) 
    ); 

    /* 
    * connect to SS and update Sheet 
    */ 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,$sheetsURL); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_VERBOSE, true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json); 

    $data = curl_exec($ch); 
    $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code 
    $curl_errno = curl_errno($ch); 
    $curl_error = curl_error($ch); 
    $information = curl_getinfo($ch); 

    curl_close($ch); 

    $ssArray = json_decode ($data, true); // make an XML object 

    /* 
    * did connection work 
    */ 

    if ($status_code != 200) { 
     echo "Oh No! Update Error: (". $ssArray['errorCode'] .") ". $ssArray['message'] ."\n"; 
    } else { 

     //var_dump($ssArray); 

     if ($ssArray['resultCode'] == 0){ 
      echo "Updated: ".$values['store']; 
     }else{ 
      echo "Oh No! Update Error: (". $ssArray['errorCode'] .") ". $ssArray['message'] ."\n"; 
     } 

    } 

} 

更多細節:http://smartsheet-platform.github.io/api-docs/#add-row-s