使用我个人的 clickup 令牌从 Google Apps 脚本进行 clickup api 调用

Using my personal clickup token to make a clickup api call from Google Apps Script

function getClickupTeam() {
  let response = UrlFetchApp.fetch(clickupUrl + "team", {
    "method": "GET",
    "Authorization": clickupToken,
    "muteHttpExceptions": true
  })
  Logger.log(response)
  let json = JSON.parse(response);
  Logger.log(json);
}

此 URLFetchApp 调用 returns {ECODE=OAUTH_017, err=Authorization header required} 即使我在请求中包含了我的个人点击令牌。我错过了什么吗?任何帮助将不胜感激。

在通过 https://clickup.com/api 对该主题进行一些研究时,我偶然发现了一些代码。对于不同的事情有几个不同的,我推荐第一个,JavaScript(因为这是最接近你目前所做的)。在评论中你说它是为了编辑任务,所以这就是这段代码的目的。

javascript

var request = new XMLHttpRequest();

request.open('PUT', 'https://api.clickup.com/api/v1/task/{task_id}');

request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Authorization', '"access_token"');

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

var body = {
  'name': 'New Task Name',
  'content': 'New Task Content',
  'assignees': {
    'add': [
      1
    ],
    'rem': [
      2
    ]
  },
  'status': 'Closed',
  'priority': 3,
  'due_date': '1508369194377'
};

request.send(JSON.stringify(body));

卷曲

curl --include \
     --request PUT \
     --header "Content-Type: application/json" \
     --header "Authorization: "access_token"" \
     --data-binary "{
    \"name\": \"New Task Name\",
    \"content\": \"New Task Content\",
    \"assignees\": {
        \"add\" : [
            1
        ],
        \"rem\" : [
            2
        ]
    },
    \"status\": \"Closed\",
    \"priority\": 3,
    \"due_date\": \"1508369194377\"
}" \
'https://api.clickup.com/api/v1/task/{task_id}'

node.js

var request = require('request');

request({
  method: 'PUT',
  url: 'https://api.clickup.com/api/v1/task/{task_id}',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': '\'access_token\''
  },
  body: "{  \"name\": \"New Task Name\",  \"content\": \"New Task Content\",  \"assignees\": {    \"add\": [      1    ],    \"rem\": [      2    ]  },  \"status\": \"Closed\",  \"priority\": 3,  \"due_date\": \"1508369194377\"}"
}, function (error, response, body) {
  console.log('Status:', response.statusCode);
  console.log('Headers:', JSON.stringify(response.headers));
  console.log('Response:', body);
});

这是针对生产的,如果您需要 mock serverdebugging proxy

,请告诉我

看起来您的请求格式不正确(请务必查看 UrlFetchApp.fetch(url, params) 方法的参考文档。)Authorization header 应该是明确的 headers object。另外,您不需要将方法设置为 GET,因为它是默认值。

在发出 POST 请求时要记住的其他事项 - Google Apps 脚本有一个有趣的怪癖,您必须在其中定义 Content-Type header 使用 contentType 属性。如果您尝试在 headers object 中设置 header if 将被默认覆盖(application/x-www-form-urlencoded 我相信)。

下面是您设置 GET 请求的方式:

function getClickupTeam() {
    let response = UrlFetchApp.fetch(clickupUrl + "team", {
        "muteHttpExceptions": true,
        "headers": {
            "Authorization": clickupToken
        }
    }
    
    console.log(response.getContentText());
    let json = JSON.parse(response.getContentText());
    
    console.log(json);
   
);

对于 POST 带有 JSON 有效载荷的请求,你会做这样的事情:

function getClickupTeam() {
    let response = UrlFetchApp.fetch(clickupUrl + "team", {
        "method": "POST",
        "contentType": "application/json",
        "muteHttpExceptions": true,
        "headers": {
            "Authorization": clickupToken
        },
        "payload": JSON.stringify({
            "key": "value"
        });
    }
    
    console.log(response.getContentText());
    let json = JSON.parse(response.getContentText());
    
    console.log(json);
   
);