登录
首页 >  Golang >  Go问答

使用 Curl 命令调用管道 API

来源:stackoverflow

时间:2024-03-22 23:09:39 273浏览 收藏

在使用 curl 命令调用管道 API 添加项目成员时遇到错误,提示“项目必须有名称”。文章指出,原始命令中存在多个错误,包括指定了两个事务,但只应用了一个。通过调整命令并指定要添加成员的项目,可以解决此错误。正确的命令格式如下: `curl https://test-caxzj6a226zp.phacility.com/api/project.edit \ -d api.token=api-[token] \ -d transactions[0][type]=members.add \ -d transactions[0][value][0]=[user-phid] \ -d objectIdentifier=[project-phid]`

问题内容

我一直在尝试使用curl调用管道api来将成员添加到特定项目并编写以下命令:

curl https://test-caxzj6a226zp.phacility.com/api/project.edit -d api.token=api-[令牌] -d 交易[0][类型]=父-d 交易[0][ value]=[project-phid] -d transactions[0][type]=members.add -d transactions[0][value][]=[user-phid]

我已按照 https://secure.phabricator.com/conduit/method/project.edit/ 上的说明进行操作,并且能够查询 project.search 和 user.search。但project.edit给我带来了麻烦。任何帮助将不胜感激。

PS:我收到以下错误:{"result":null,"error_code":"ERR-CONDUIT-CORE","error_info":"验证错误:\n - 项目必须有名称。"}


解决方案


您的通话中有一些错误。第一个是您指定要在同一索引中应用的两个事务。稍微格式化您的调用,我们得到:

curl https://test-caxzj6a226zp.phacility.com/api/project.edit \
    -d api.token=api-[token] \
    -d transactions[0][type]=parent \
    -d transactions[0][value]=[project-phid] \
    -d transactions[0][type]=members.add \
    -d transactions[0][value][]=[user-phid]

transactions[0] 有两个定义,如果要应用多个转换,则需要增加索引:

curl https://test-caxzj6a226zp.phacility.com/api/project.edit \
    -d api.token=api-[token] \
    -d transactions[0][type]=parent \
    -d transactions[0][value]=[project-phid] \
    -d transactions[1][type]=members.add \
    -d transactions[1][value][]=[user-phid]

现在,您实际上并没有提到想要更改父项目,因此我将删除该事务。

curl https://test-caxzj6a226zp.phacility.com/api/project.edit \
    -d api.token=api-[token] \
    -d transactions[0][type]=members.add \
    -d transactions[0][value][]=[user-phid]

要添加的用户也是一个数组,因此您需要为该参数指定索引:

curl https://test-caxzj6a226zp.phacility.com/api/project.edit \
    -d api.token=api-[token] \
    -d transactions[0][type]=members.add \
    -d transactions[0][value][0]=[user-phid]

您可以使用 -d transactions[0][value][1]=[user-phid]-d transactions[0][value][2]=[user-phid] 添加其他用户等等

最后,您还需要指定要将成员添加到哪个项目,因为它是必填字段。为此,请指定项目的数字 id(您可以在其 url /project/view/1/ 中找到它)、其 phid 或其名称/slug。

curl https://test-caxzj6a226zp.phacility.com/api/project.edit \
    -d api.token=api-[token] \
    -d transactions[0][type]=members.add \
    -d transactions[0][value][0]=[user-phid] \
    -d objectIdentifier=[project-phid]

您实际上可以从管道应用程序内向管道提交测试调用,提交后,示例部分中的一个选项卡将显示通过 api 执行该操作所需的curl 调用:

https://secure.phabricator.com/conduit/method/project.edit/

以上就是《使用 Curl 命令调用管道 API》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>