2016-02-26 50 views
0

連勝API:https://www.streak.com/api/谷歌Apps腳本POST請求連勝API

我試圖用氣體UrlService這種連勝的API,發現GET請求正確的語法。但我不認爲認沽和後期的分辯語法:

(1)F.E.創建框

var RequestArguments = { 
     "contentType": "application/json", 
     "headers":{ 
     "User-Agent": "MY_APP_NAME", 
     "Authorization": "Basic " + Utilities.base64Encode(streakApiKey), 
     }, 
    "validateHttpsCertificates" :false, 
    "method": "PUT", 
    "????": "????" 
    }; 

    var result = UrlFetchApp.fetch(RequestUrl,RequestArguments); 

(2)f.e.編輯框

var RequestArguments = { 
    "contentType": "application/json", 
    "headers":{ 
     "User-Agent": "MY_APP_NAME", 
     "Authorization": "Basic " + Utilities.base64Encode(streakApiKey), 
    }, 
    "validateHttpsCertificates":false, 
    "method": "PUT", 
    "????": "????" 
    }; 

    var result = UrlFetchApp.fetch(RequestUrl,RequestArguments); 

回答

0

這是工作:

function editBox() { 
    var boxKey =  "xxx"; 
    var value = "{value:Test}"; 
    var fieldKey = "1001"; 
    //{name:"Deal Size", key:"1001", type:"TEXT_INPUT", lastUpdatedTimestamp:1457089319053} 

    var url = 'https://www.streak.com/api/v1/boxes/' + boxKey + '/fields/' + fieldKey; 

    var params = { 
    headers: {Authorization: 'Basic ' + Utilities.base64Encode(streakApiKey)}, 
    method: "POST", 
    payload: value, 
    contentType: 'application/json' 
    }; 

    var result = UrlFetchApp.fetch(url,params); 

    var string = result.getContentText(); 
    var Object = JSON.parse(string);  

    return Object; 
} 


function createBox() { 

    var pipelineKey = "xxx"; 
    var name = "sample box name"; 

    var url = 'https://www.streak.com/api/v1/pipelines/' + pipelineKey + '/boxes'; 

    var RequestArguments = { 
    headers: {"Authorization": "Basic " + Utilities.base64Encode(streakApiKey)}, 
    method: "PUT", 
    payload: { 
     name: name 
    } 
    }; 

    var box = UrlFetchApp.fetch(url,RequestArguments); 

    var result = JSON.parse(box.getContentText()); 

    return result; 
} 
0

我在Chrome擴展用這樣的方式,並沒有嘗試這個代碼,但應在GAS相似:

"url": "https://www.streak.com/api/v1/boxes/"+boxKey+"/fields/"+fieldKey;   
    "type": 'POST', 
    "dataType": "json", 
    "contentType": 'application/json; charset=utf-8', 
    "data": {value: yourValue} 

我花了一些時間來找出正確的組合參數(Streak API文檔在這部分中不友好),但是我在代碼中看到的內容對我來說看起來很好。它應該工作。

0

這裏是您可以使用現有的框編輯字段中的功能。創建一個新盒子將遵循相同的格式。

function editBox(boxKey, fieldKey, value) { 
    var url = 'https://www.streak.com/api/v1/boxes/' + boxKey + '/fields/' + fieldKey; 
    var params = { 
     headers: {Authorization: 'Basic ' + Utilities.base64Encode(STREAK_API_KEY + ":")}, 
     method: "POST", 
     payload: JSON.stringify({ 
      value: value 
     }), 
     contentType: 'application/json' 
    }; 
    var field = UrlFetchApp.fetch(url,params); 
    return JSON.parse(field.getContentText()); 
}