如何使用REST API用新值更新字段

How to update a field with a new value using the REST API?

本文关键字:新值 更新 字段 API 何使用 REST      更新时间:2023-09-26

我正在使用Podio,我希望能够使用Podio RESTful API更新项目。

我更具体地想将纯文本PUT放入项字段。我已经按照说明成功更新了问题字段。然而,更新导致更新字段为"无值"。我不知道如何让API用我提供的值更新字段。这是我的代码:

var path = '/item/';
var item_id = 346397274;
var value = 'value';
var field_id = 108976076;
var update = "foo"
var update_length = update.length;
var options = {
    'host': 'api.podio.com',
    'port': 443,
    'path': path + item_id + '/value/' + field_id,
    'accept': 'application/json',
    'method': 'PUT',
    'headers': {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Content-Length': update_length,
        'Authorization': 'Bearer ' + access_token
    }
}
var req = https.request(options, function(res) {
})
req.write(update);
req.end();

我想我的请求体在某种程度上必须有所不同。但是我试过各种各样的组合,我就是不能让它工作。当我运行GET请求时,所讨论字段的返回数据如下:

{ status: 'active',
  type: 'text',
  field_id: 108976076,
  label: 'Titel',
  values: [ { value: 'Old Value' } ],
  config: 
   { default_value: null,
     description: null,
     settings: { format: 'plain', size: 'small' },
     required: false,
     mapping: null,
     label: 'Titel',
     visible: true,
     delta: 0,
     hidden: false,
     unique: false },
  external_id: 'titel' }

我还尝试在请求正文中放入以下内容:var update = querystring.stringify({"value": "foo"});和:

var update = {"values": [querystring.stringify({
    "value": "foo"
    })]
};
var update = querystring.stringify(update);

我做错了什么?

请尝试以下操作:

For request body:

{"titel": "My test value"}

请求url:

https://api.podio.com/item/<item_id>/value/

All together as cURL:

curl 
    -H "Content-Type: application/json" 
    -H "Authorization: OAuth2 <access_token>" 
    -X PUT   
    -d '{"titel": "Some updates"}'
    https://api.podio.com/item/<item_id>/value/