使用 javascript 创建一个新的 Phabricator 任务

Creating a new Phabricator task with javascript

我正在尝试连接到 Phabricator 管道 API 并通过绑定到 google sheet 的 javascript 创建任务。

Conduit API 文档 linked here 并没有真正解释太多。我看过更好的 API 文档!

以下是我的想法,但这是一个 cURL,我不知道如何制作它 Javascript 或枯萎这是否可行?感谢您的帮助

curl https://secure.phabricator.com/api/maniphest.edit \
-d api.token=api-token \
-d param= [
    {
      "type": "title",
      "value": "A value from a cell on the googlesheet"
    },
    {
      "type": "description",
      "value": "A value from a cell on the googlesheet"
    },
    {
      "type": "subscribers.add",
      "value": "A value from a cell on the googlesheet"
    }
  ] \

一般来说步骤是:

首先,在以下位置生成一个 API 令牌: https://phabricator.yourdomain.com/settings/user/username/page/apitokens/

其中 phabricator.yourdomain.com 必须由您安装 Phabricator 的子域更改,username 必须由您的管理用户名更改。

然后,假设您在 phabricator.yourdomain.com 中安装了 Phabricator,您可以使用 URL 以下类型的

请求 API 方法

https://phabricator.yourdomain.com/api/method_name?parameter1=value1&parameter2=value2...

其中 method_name 必须替换为该目录中真实方法的描述符: https://secure.phabricator.com/conduit/

例如,如果你想读取任务编号125的内容,生成一个API令牌值api-svhcp2a3qmgkkjfa5f6sh7cm4joz,使用方法maniphest.info来像这样完成 URL:

http://phabricator.yourdomain.com/api/maniphest.info?api.token=api-svhcp2a3qmgkkjfa5f6sh7cm4joz&task_id=125&output=json

此 URL 可以直接在您首选的浏览器中进行测试,以获得包含有关任务号 125 的信息的 JSON 响应(确保任务 ID 存在)。 Firefox 甚至会以 human-readable 的方式显示返回的 JSON。

然后可以将这些有效的 URL 插入 Javascript 作为

window.location.href=http://phabricator.yourdomain.com/api/maniphest.info?api.token=api-svhcp2a3qmgkkjfa5f6sh7cm4joz&task_id=125&output=json

或作为异步 Ajax 调用。

我遇到了与您类似的问题(我将 HTTParty 与 Ruby 一起使用)。 为了解决它,我使用了以下正文(使用您的示例):

"transactions[0][type]=title&transactions[0][value][0]=A value from a cell on the googlesheet&transactions[1][type]=description&transactions[1][value]=A value from a cell on the googlesheet&transactions[2][type]=subscribers.add&transactions[2][value][0]=A value from a cell on the googlesheet"