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

如何在Zoho Books中以自定义字段数组为参数获取发票?

实现Zoho Books发票API多自定义ID筛选的步骤

我们在创建发票时添加了名为property_Id的自定义字段,目前通过传入单值参数cf_property_d="12345"来获取发票列表。现在希望传入包含多个ID的数组作为该参数,以获取包含其中任意ID的发票列表,请问需执行哪些步骤实现?

static async list(accessToken: string) {

        const params: any = {
            organization_id: ZohoConfig.organizationId,
            page: query?.page,
            per_page: query?.per_page,

        // 当前可用写法
        cf_property_d:"12345"
            // 期望实现的写法
            // 我希望获取包含列表中任意ID的发票数据。
        cf_property_d:["12345","12346","123888","999999","1111222"]

        };

        const url = `https://books.zoho.com/api/v3/invoices?`;

        const config = {
            method: 'GET',
            url: url,
            params,
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Zoho-oauthtoken 123456789`
            },
        };
        axios(config)
    .then(response => {
    
            console.log(response.data);
    })
    .catch(error => {
            console.log(error);
    });
    }

实现步骤

  • 第一步:确认Zoho Books的多值参数规则
    Zoho Books API处理多值自定义字段筛选,通常有两种格式:要么把多个ID用逗号拼成一个字符串,要么重复参数名(比如cf_property_d=12345&cf_property_d=12346)。优先试逗号分隔,这是多数API的通用做法。

  • 第二步:修改代码里的参数处理逻辑
    把目标ID数组转成逗号分隔的字符串,替换原来的单值参数。调整后的代码如下:

    static async list(accessToken: string) {
        // 定义需要筛选的多个property ID数组
        const targetPropertyIds = ["12345","12346","123888","999999","1111222"];
        
        const params: any = {
            organization_id: ZohoConfig.organizationId,
            page: query?.page,
            per_page: query?.per_page,
            // 将数组转为逗号分隔的字符串
            cf_property_d: targetPropertyIds.join(',')
        };
    
        const url = `https://books.zoho.com/api/v3/invoices`;
    
        const config = {
            method: 'GET',
            url: url,
            params,
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Zoho-oauthtoken ${accessToken}`
            },
        };
        
        try {
            const response = await axios(config);
            console.log(response.data);
        } catch (error) {
            console.log(error);
        }
    }
    
  • 第三步:如果逗号分隔不生效,尝试重复参数格式
    要是上面的方法没效果,直接传数组试试——Axios会自动把数组转成重复的参数键值对(比如cf_property_d=12345&cf_property_d=12346),只需要把参数改成数组形式:

    cf_property_d: targetPropertyIds
    

    注意:这种方式需要Zoho Books API支持重复参数,得实际测试验证。

  • 第四步:测试并调试请求
    发送请求后查看实际生成的URL参数,确认格式是否符合要求;如果返回错误,查Zoho官方文档里自定义字段多值筛选的具体规则,再调整参数格式。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 12:13:07