简体   繁体   中英

POST projects in Toggl through API

I'm developing an API to integrate the Knack with Toggl . So, I need to post some data in the Toggl using an API that will be running in Google Script (JavaScript ).

When I try to post somes projects in the Toggl, I receive the following error: "Request failed for https://www.toggl.com/api/v8/projects returned code 400. Truncated server response: Project can't be blank (use muteHttpExceptions option to examine full response) (line 61, file "")"

My source code is:

function sendDataToToggl(){
   var apiToken = '936e292eaccd99b40358edea25452880';  
   var unamepass = apiToken + ":api_token"; 
   var digest = Utilities.base64Encode(unamepass);
   var digestfull = "Basic " + digest;
   var url = "https://www.toggl.com/api/v8/projects";
   var data = {"project":{"name":"An awesome project","wid":1034130,"template_id":1793088,"is_private":true,"cid":123397}};
   var options = { 
                   "Content-Type": "application/json",
                   "method": "post",
                   "headers": {"Authorization": digestfull},
                   "payload": data
                   //"muteHttpExceptions": true 
                 };
   var response = UrlFetchApp.fetch(url, options);
}

Change options:

Also, as you publicly posted your API key, you might want to get a new one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM