You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Podio添加多标签项时触发PodioBadRequestError无效整数值问题

Fixing PodioBadRequestError When Adding Specific Tags via PHP SDK

Let's break down why you're hitting this 400 error and how to fix it:

Root Cause Analysis

The most likely issue is that the hospital, clinic, or urgent_care tag IDs you're using don't belong to the tags-2 category field in your Podio customer app. Podio strictly validates that category field values match the pre-configured options for that specific field—using an ID from another field (like the separate OrganizationType field hinted at by your PODIO_ORGANIZATION_TYPE_ID constant) will trigger this "invalid integer type" error, even if the ID itself is a valid integer.

Your working newsletter_subscribed tag works because its ID is actually an option in the tags-2 field (confirmed in your Postman response), while the other tags belong to a different category field.

Step-by-Step Fixes

1. Verify Tag IDs Belong to tags-2

First, confirm which IDs are valid for the tags-2 field. Use the Podio PHP SDK to fetch the field's configuration and check its options:

// Add this snippet to your code (or run it standalone) to check valid options
$field = PodioField::get(PODIO_CUSTOMER_APP_ID, 'tags-2');
print_r($field->config['settings']['options']);

Look for the id values in the output—if your clinic/hospital IDs aren't listed here, you're using the wrong IDs for this field. You'll need to either:

  • Add those tags as options directly to the tags-2 field in your Podio app settings, or
  • Use the correct category field (likely the one linked to PODIO_ORGANIZATION_TYPE_ID) for storing organization type tags.

2. Adjust the Value Format for Category Fields

While the Podio SDK accepts raw ID arrays for category fields, switching to an explicit format can resolve type-related edge cases. Modify your tag assignment code to use the structured ['id' => $tagId] format:

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' => []
        ],
    ];

    // Add newsletter tag with explicit format
    if ($this->Newsletter && defined('PODIO_NEWSLETTER_TAG_ID')){
        $item['fields']['tags-2'][] = ['id' => (int)PODIO_NEWSLETTER_TAG_ID];
    }

    // Add organization type tags (ensure IDs are valid for tags-2 first!)
    if($this->OrganizationType){
        $tagId = null;
        if($this->OrganizationType == "Clinic" && defined('PODIO_ORGANIZATION_TYPE_CLINIC_TAG_ID')){
            $tagId = PODIO_ORGANIZATION_TYPE_CLINIC_TAG_ID;
        } else if($this->OrganizationType == "Hospital" && defined('PODIO_ORGANIZATION_TYPE_HOSPITAL_TAG_ID')){
            $tagId = PODIO_ORGANIZATION_TYPE_HOSPITAL_TAG_ID;
        }
        
        if($tagId){
            $item['fields']['tags-2'][] = ['id' => (int)$tagId];
        }
    }

    try {
        $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->getMessage());
        return 'An error occurred while updating Podio. Please try again. If the error persists, contact support.';
    }
}

3. Fix Constant Data Types

Your current constants define tag IDs as strings (wrapped in quotes). Podio expects integer IDs, so update your config to remove the quotes:

// Replace string definitions with integers
define('PODIO_NEWSLETTER_TAG_ID', 96); // Match the ID from your Postman response
define('PODIO_ORGANIZATION_TYPE_CLINIC_TAG_ID', 16);
define('PODIO_ORGANIZATION_TYPE_HOSPITAL_TAG_ID', XXX); // Replace with valid tags-2 ID

Final Notes

If you meant to store organization type tags in a separate field (not tags-2), adjust your $item array to target that field's external ID instead. For example, if the organization type field has an external ID of organization-type, add:

$item['fields']['organization-type'][] = ['id' => $tagId];

内容的提问来源于stack exchange,提问作者Guyute

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 17:42:52