尝试添加在其字段中具有多个标签的项目时,Podio抛出PodioBadRequestError invalid_value int

问题描述

我正在尝试向我的Podio应用添加客户(Podio项目)。正在从PHP应用程序中以编程方式添加此客户。客户上有几个字段:名称,地址,电子邮件标题,电话号码和标签数组。添加标签后,颜色会更改为突出显示。 在以前的迭代中,我已经使用要突出显示标签值的ID成功添加了另一个标签(newsletter_subscribed)。现在,当我尝试添加其他标签(医院,诊所或紧急护理)时,它会引发PodioBadRequestError。引用的错误是所使用的ID为且类型(整数)无效。

通过查看当现有客户在我的Podio客户应用程序中手动创建时返回的JSON,我得到了标签ID的值。当我查看JSON中的ID字段时,它们绝对是整数,我也尝试过字符串。我尝试的所有操作都会在我要添加的ID上抛出400 Bad Request。 我一生都无法弄清楚为什么添加标签ID时会引发错误

下面是应用程序组合在一起的方式:

这是构建和发送请求的代码

public function addToPodio()
{
         $address = $this->Address . "," .
                    $this->Address2 . "," .
                    $this->City . "," .
                    $this->State . " " .
                    $this->Zip;
         
         $item = [
            'fields' => [
                'name'          => $this->PrimaryContactFirstName,'last-name'     => $this->PrimaryContactLastName,'email-address' => ['type' => 'work','value' => $this->PrimaryContactEmail],'phone-number'  => ['type' => 'work','value' => $this->PrimaryContactPhone],'address'       => $address,'organization'  => [$this->CompanyName],'tags-2' => []
             ],];

           if ($this->Newsletter && defined('POdio_NEWSLETTER_TAG_ID')){
            $item['fields']['tags-2'][] = POdio_NEWSLETTER_TAG_ID;
           }

           if($this->OrganizationType && defined('POdio_ORGANIZATION_TYPE_ID')){
        
            if($this->OrganizationType == "Clinic"){
                $item['fields']['tags-2'][] = POdio_ORGANIZATION_TYPE_CLINIC_TAG_ID;
            }
            else if($this->OrganizationType == "Hospital"){
                $item['fields']['tags-2'][] = POdio_ORGANIZATION_TYPE_HOSPITAL_TAG_ID;
            }
      
        try {
             //This is where the request is being made
            $customer = PodioItem::create(POdio_CUSTOMER_APP_ID,$item);
            $this->PodioId = $customer->item_id;
            $this->write();

         } catch (Exception $e) {
           error_log('We encountered an error adding your item to Podio' . $e);
           return 'An error occurred while updating Podio. Please try again. If the error...';
         }

这是传递给要发送到Podio API的请求的PHP $ item:

    Array
    (
        [fields] => Array
            (
                [name] => Joe
                [last-name] => Test
                [phone-number] => Array
                    (
                        [type] => work
                        [value] => 8675309
                    )

                [address] => 123 Main Road,East Test,NY 12345
                [organization] => Array
                    (
                       [0] => Another Test
                    )

                [tags-2] => Array
                    (
                       [0] => 16
                       [1] => 96
                    )

           )

    )

这是配置文件,其中包含连接到Podio API,进行身份验证以及所有这些工作所需的所有常量,秘密令牌和ID。下面的混淆示例:

define('POdio_CUSTOMER_APP_ID','xxxxx-obfuscated-xxxxx');
define('POdio_CUSTOMER_APP_TOKEN','xxxxx-obfuscated-xxxxx');
define('POdio_CLIENT_SECRET','xxxxx-obfuscated-xxxxx');
define('POdio_CLIENT_ID','xxxxx-obfuscated-xxxxx');
define('POdio_ORGANIZATION_TYPE_ID','xxxxx-obfuscated-xxxx');
define('POdio_NEWSLETTER_TAG_ID','xxxxx-obfuscated-xxxxx');
define('POdio_ORGANIZATION_TYPE_CLINIC_TAG_ID','xxxxx-obfuscated-xxxxx');

Podio::setup(POdio_CLIENT_ID,POdio_CLIENT_SECRET,[
    'session_manager' => Injector::inst()->get(PodioSession::class),'curl_options' => array(),]);

下面是我用来获取ID值的JSON。我是从邮递员对API的请求中获得的。没有所有身份验证的请求的基本形式如下:

podio.com/MY_POdio_ACCOUNT_NAME/app/APPLICATION_ID/item/ITEM_ID
  • 请注意:为简便起见,我删除了许多主要字段,例如“地址”和“组织”,因此它与上面的PHP请求对象不完全匹配。

      {
        "id": 0000,"item_id": 00000,"revision": 0,"app": null,"app_item_id": 00000,"app_item_id_formatted": "POdio_Field_ID:00000","external_id": null,"title": "TEST ITEM","fields": [
          {
            "id": 0000,"field_id": 0000,"type": "text","external_id": "name","label": "First Name","values": [
              {
                "value": "Joe"
              }
            ],"config": {
              "settings": {
                "format": "plain","size": "small"
              },"mapping": "contact_name","label": "First Name"
            },"humanized_value": "Joe"
          },{
            "id": 0000,"external_id": "last-name","label": "Last Name","values": [
              {
                "value": "<p>Test<br /></p>"
              }
            ],"config": {
              "settings": {
                "format": "html","size": "large"
              },"mapping": null,"label": "Last Name"
            },"humanized_value": "Test"
          },"type": "phone","external_id": "phone-number","label": "Phone Number","values": [
              {
                "type": "work","value": "867-5309"
              }
            ],"config": {
              "settings": {
                "call_link_scheme": "callto","possible_types": [
                  "mobile","work","home","main","work_fax","private_fax","other"
                ]
              },"mapping": "contact_phone","label": "Phone Number"
            },"humanized_value": "8675309"
          },{
            "id": 11111,"field_id": 11111,"type": "category","external_id": "tags-2","label": "Tags","values": [
              {
                "value": {
                  "status": "active","text": "Clinic","id": 16,"color": "DCEBD8"
                }   
              },{
                "value": {
                  "status": "active","text": "Newlsetter_subscribed","id": 96,"color": "DCEBD8"
                }
             }
            ],"config": {
              "settings": {
                "multiple": true,"options": [
                  {
                    "status": "active","text": "Mktng:test1/2020","id": 150,"color": "DCEBD8"
                  },{
                    "status": "active","text": "Mktng:Test2/2020","id": 3,"text": "SampleTest","id": 48,{
                    "status": "deleted","text": "Test Center","id": 139,"text": "Sample Center","id": 99,"text": "Testing Center","id": 140,"color": "DCEBD8"
                  }
                ],"display": "inline"
              },"label": "Tags"
            },"humanized_value": "Clinic; Newsletter;"
          }
    

此JSON继续用于页面页面,我只包含了我的问题的相关字段。

解决方法

看起来是因为组织值而不是标签值引发了错误。

对于类别字段,整数索引数组是正确的。

[tags-2] => [ 16,96 ]

对于应用字段,您需要提供一组整数项 ID。

[organization] => [ 12345 ]

但是你上面的代码正在发送一个字符串数组:

[organization] => [ "Another Test" ]

那行不通。