插入记录

目的

向模块添加新实体。

请求URL

https://www.zohoapis.com.cn/crm/v2/{module_api_name}

module_api_name - 模块的API名称

获取记录列表中支持的模块在这里也支持。

备注:

要插入一条记录,只需在输入中发送一个JSON对象和必要的键和值。

请求方法

POST

范围

scope=ZohoCRM.modules.all
(或)
scope=ZohoCRM.modules.{module_name}.{operation_type}

可能的模块名称可能的操作类型
线索,客户,联系人,商机,市场活动,任务,服务支持,事件,通话,解决方案,产品,供货商,价格表,报价单,销售订单,采购订单,发货单,自定义模块和备注ALL - 完全访问记录
WRITE - 编辑模块中的记录
CREATE - 在模块中创建记录

可能的错误

HTTP状态错误码消息原因"Details" 键值
400INVALID_MODULE给出的模块名称似乎无效无效的模块名称或没有选项卡权限,或者模块可能已从已组织的模块中删除---
400INVALID_MODULE在API中不支持给定的模块当前API不支持文档和项目等模块。(一旦支持了这些模块,就不会显示此错误。)---
403NO_PERMISSION拒绝创建'{modulename}'没有插入记录的权限---
400MANDATORY_NOT_FOUND未找到所需字段。如果数据键不可用{
"api_name": "data"
}
400INVALID_DATA无效的数据如果数据键具有无效的数据类型{ "expected_data_type":"jsonarray",
"api_name": "data"
},
202INVALID_DATA (在记录索引处)无效的数据如果传递的记录不是JSON对象{
"expected_data_type":"jsonobject",
"index": 0
}
201MANDATORY_NOT_FOUND未找到所需字段如果必填字段不可用{
"api_name":"Last_Name"
}
202INVALID_DATA无效的数据如果数据类型不匹配{
"expected_data_type":"double",
"api_name":"Decimal_1"
}

备注:

  • 如果字段值长度大于为该字段定义的最大长度则抛出错误。

  • 如果在函数中使用API,并且字段值长度超过限制,则该函数将从API接收错误响应。例如:如果“文本字段”的最大长度定义为10,那么API中给出的值不能是“12345678901”,因为它有11个字符。

  • 对于每个基于惟一字段的插入记录API调用,都会检查重复项。

  • 每次API调用最多可以插入100条记录。

  • 在输入中提供字段API名称以及要填充的相应值。

  • trigger输入可以是workflowapprovalblueprint。如果没有提到触发器,将执行与API相关的工作流、审批和蓝图。输入触发器值为[]就不执行工作流。

  • 具有子表单详细信息的记录也可以使用记录API插入CRM。请参考子表单API了解有关在记录中添加子表单信息的更多信息

  • $approvedkey用于设置要在审批模式下创建的记录。它主要用于从web表单获取线索和联系人。

  • 请参考响应结构了解有关JSON键、值及其描述的详细信息。您还可以使用每个模块的示例响应作为输入,在相应模块中插入、更新或维护记录。

示例属性

属性示例
单行"Single_Line_1": "This is single line",
多行"Multi_Line_1": "This is the first line \n Now for the second Line",
邮箱"Email_1": "p.boyle@zylker.com",
电话"Phone_1": "9900000000",
选择列表"Picklist_1" : "In Progress",
多选列表"Multi-Select_Picklist" : [
"{Option_1}",
"{Option_2}",
"{Option_3}"
],
日期"Date_1": "2017-08-16",
日期/时间"Date_Time": "2017-08-16T14:32:23+05:30",
数字"Number_1": 575,
货币"Currency_1": 250000,
小数"Decimal_1": 250000.50,
百分比""Percent_1": 25,
长整型"Long_Integer_1": "250000000000000",
复选框"Checkbox_1": false,
URLURL_1": "https://www.zoho.com/crm",
查找"Lookup" : {
"name" : "James"
"id" : "425248000000104001"
},
Record Owner"Owner": {
"name" : "Patricia"
"id": "425248000000104003"
},
Layout"Layout": {
"name" : "Custom Layout 1"
"id": "425248000000404433"
},

示例请求

在这个请求中,"@newlead.json" 包含了示例输入数据。


				curl "https://www.zohoapis.com.cn/crm/v2/Leads"
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-d "@newlead.json"
-X POST			

示例输入


				{
    "data": [
       {
            "Company": "Zylker",
            "Last_Name": "Daly",
            "First_Name": "Paul",
            "Email": "p.daly@zylker.com",
            "State": "Texas"
        },
       {
            "Company": "Villa Margarita",
            "Last_Name": "Dolan",
            "First_Name": "Brian",
            "Email": "brian@villa.com",
            "State": "Texas"
        }
    ],
    "trigger": [
        "approval",
        "workflow",
        "blueprint"
    ]
}			

示例响应


				{
    "data": [
       {
            "message": "record added",
            "details": {
                "created_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "id": "4108880000478027",
                "modified_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "modified_time": "2016-04-28T17:59:21+05:30",
                "created_time": "2016-04-28T17:59:21+05:30"
            },
            "status": "success",
            "code": "SUCCESS"
        },
       {
            "message": "record added",
            "details": {
                "created_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "id": "4108880000478027",
                "modified_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "modified_time": "2016-04-28T17:59:21+05:30",
                "created_time": "2016-04-28T17:59:21+05:30"
            },
            "status": "success",
            "code": "SUCCESS"
        }
    ]
}			

示例请求


				List<ZCRMRecord> records = new ArrayList<>();
ZCRMRecord record1 = new ZCRMRecord("Products"); //模块API名称
ZCRMUser owner = ZCRMUser.getInstance(12345678l);// 用户ID
record1.setOwner(owner);
record1.setFieldValue("Product_Name", "mass_create1");// 字段API名称及其值
ZCRMRecord record2 = new ZCRMRecord("Products"); //模块API名称
ZCRMUser owner = ZCRMUser.getInstance(5676875678l);// 用户ID
record2.setOwner(owner);
record2.setFieldValue("Product_Name", "mass_create2");// 字段API名称及其值
records.add(record1);
records.add(record2);
ZCRMModule module = ZCRMModule.getInstance("Products"); //模块API名称
BulkAPIResponse response = module.createRecords(records);
List<ZCRMRecord> insertedRecords = (List<ZCRMRecord>) response.getData();
List<BulkAPIResponse.EntityResponse> entityResponses =
response.getEntityResponses();// 检查请求的状态
String rec1Status = entityResponses.get(0).getStatus();//检查记录1的状态
String rec2Status = entityResponses.get(1).getStatus();//检查记录2的状态			

Sample Input


				{
    "data": [
       {
            "Company": "Zylker",
            "Last_Name": "Daly",
            "First_Name": "Paul",
            "Email": "p.daly@zylker.com",
            "State": "Texas"
        },
       {
            "Company": "Villa Margarita",
            "Last_Name": "Dolan",
            "First_Name": "Brian",
            "Email": "brian@villa.com",
            "State": "Texas"
        }
    ],
    "trigger": [
        "approval",
        "workflow",
        "blueprint"
    ]
}			

示例响应


				{
    "data": [
       {
            "message": "record added",
            "details": {
                "created_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "id": "4108880000478027",
                "modified_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "modified_time": "2016-04-28T17:59:21+05:30",
                "created_time": "2016-04-28T17:59:21+05:30"
            },
            "status": "success",
            "code": "SUCCESS"
        },
       {
            "message": "record added",
            "details": {
                "created_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "id": "4108880000478027",
                "modified_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "modified_time": "2016-04-28T17:59:21+05:30",
                "created_time": "2016-04-28T17:59:21+05:30"
            },
            "status": "success",
            "code": "SUCCESS"
        }
    ]
}			

示例请求


				$zcrmModuleIns = ZCRMModule::getInstance("Invoices");
$bulkAPIResponse=$zcrmModuleIns->createRecords($recordsArray); // $recordsArray - ZCRMRecord实例数组,其中包含创建所需的数据。
$entityResponses = $bulkAPIResponse->getEntityResponses();
foreach($entityResponses as $entityResponse)
{
if("success"==$entityResponse->getStatus())
{
echo "Status:".$entityResponse->getStatus();
echo "Message:".$entityResponse->getMessage();
echo "Code:".$entityResponse->getCode();
$createdRecordInstance=$entityResponse->getData();
echo "EntityID:".$createdRecordInstance->getEntityId();
echo "moduleAPIName:".$createdRecordInstance->getModuleAPIName();
….
}
}
Sample Invoice record instance with filled data
$record=ZCRMRecord::getInstance("Invoices",null);
$record->setFieldValue("Subject","Iphone sale to John");
$record->setFieldValue("Account_Name","410405000001016021");
$productInstance=ZCRMRecord::getInstance("Products",410405000001108011);
$lineItem=ZCRMInventoryLineItem::getInstance($productInstance);
$taxInstance1=ZCRMTax::getInstance("Sales Tax");
$taxInstance1->setPercentage(2);
$taxInstance1->setValue(10);
$lineItem->addLineTax($taxInstance1);
$taxInstance1=ZCRMTax::getInstance("Vat");
$taxInstance1->setPercentage(12);
$taxInstance1->setValue(60);
$lineItem->addLineTax($taxInstance1);
$lineItem->setQuantity(100);
$lineItem->setDiscount(0.5);
$record->addLineItem($lineItem);			

示例输入


				{
    "data": [
       {
            "Company": "Zylker",
            "Last_Name": "Daly",
            "First_Name": "Paul",
            "Email": "p.daly@zylker.com",
            "State": "Texas"
        },
       {
            "Company": "Villa Margarita",
            "Last_Name": "Dolan",
            "First_Name": "Brian",
            "Email": "brian@villa.com",
            "State": "Texas"
        }
    ],
    "trigger": [
        "approval",
        "workflow",
        "blueprint"
    ]
}			

示例响应


				{
    "data": [
       {
            "message": "record added",
            "details": {
                "created_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "id": "4108880000478027",
                "modified_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "modified_time": "2016-04-28T17:59:21+05:30",
                "created_time": "2016-04-28T17:59:21+05:30"
            },
            "status": "success",
            "code": "SUCCESS"
        },
       {
            "message": "record added",
            "details": {
                "created_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "id": "4108880000478027",
                "modified_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "modified_time": "2016-04-28T17:59:21+05:30",
                "created_time": "2016-04-28T17:59:21+05:30"
            },
            "status": "success",
            "code": "SUCCESS"
        }
    ]
}			

示例请求


				def create_records(self):
    try:
        record_ins_list=list()
        for i in range(0,2):
            record=ZCRMRecord.get_instance('Invoices') #模块API名称
            record.set_field_value('Subject', 'Invoice'+str(i))
            record.set_field_value('Account_Name', 'IIIT')
            user=ZCRMUser.get_instance(440872000000175001,'Python Automation User1')
            record.set_field_value('Owner',user)
            line_item=ZCRMInventoryLineItem.get_instance(ZCRMRecord.get_instance("Products",440872000000224005))
            line_item.discount=10
            line_item.list_price=8
            line_item.description='Product Description'
            line_item.quantity=100
            line_item.tax_amount=2.5
            taxIns=ZCRMTax.get_instance("Vat")
            taxIns.percentage=5
            line_item.line_tax.append(taxIns)
            record.add_line_item(line_item)
            record_ins_list.append(record)
        resp=ZCRMModule.get_instance('Invoices').create_records(record_ins_list)
        print resp.status_code
        entity_responses=resp.bulk_entity_response
        for entity_response in entity_responses:
            print entity_response.details
            print entity_response.status
            print entity_response.message
            print entity_response.code
            print entity_response.data.entity_id
            print entity_response.data.created_by.id
            print entity_response.data.created_time
            print entity_response.data.modified_by.id
            print "\n\n"
    except ZCRMException as ex:
        print ex.status_code
        print ex.error_message
        print ex.error_code
        print ex.error_details
        print ex.error_content			

Sample Input


				{
    "data": [
       {
            "Company": "Zylker",
            "Last_Name": "Daly",
            "First_Name": "Paul",
            "Email": "p.daly@zylker.com",
            "State": "Texas"
        },
       {
            "Company": "Villa Margarita",
            "Last_Name": "Dolan",
            "First_Name": "Brian",
            "Email": "brian@villa.com",
            "State": "Texas"
        }
    ],
    "trigger": [
        "approval",
        "workflow",
        "blueprint"
    ]
}			

示例响应


				{
    "data": [
       {
            "message": "record added",
            "details": {
                "created_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "id": "4108880000478027",
                "modified_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "modified_time": "2016-04-28T17:59:21+05:30",
                "created_time": "2016-04-28T17:59:21+05:30"
            },
            "status": "success",
            "code": "SUCCESS"
        },
       {
            "message": "record added",
            "details": {
                "created_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "id": "4108880000478027",
                "modified_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "modified_time": "2016-04-28T17:59:21+05:30",
                "created_time": "2016-04-28T17:59:21+05:30"
            },
            "status": "success",
            "code": "SUCCESS"
        }
    ]
}			

示例请求:创建价格表记录


				语法:
zoho.crm.bulkCreate(<module String>,<dataList List>,<optionalDataMap Map>,<connectionName String>,<userAccess Boolean>);
mandatory : module,dataList

示例请求:
resp = zoho.crm.bulkCreate("Price_Books", [{"Owner": {"id": "7000000031553"},"Active": true,"Pricing_Details": [{"to_range": 5,"discount": 0,"from_range": 1},{"to_range": 11,"discount": 1,"from_range": 6},{"to_range": 17,"discount": 2,"from_range": 12},{"to_range": 23,"discount": 3,"from_range": 18},{"to_range": 29,"discount": 4,"from_range": 24}],"Pricing_Model": "Differential","Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.","Price_Book_Name": "Price_Book_Name oops1"},{"Owner": {"id": "7000000031553"},"Active": true,"Pricing_Details": [{"to_range": 5,"discount": 0,"from_range": 1},{"to_range": 11,"discount": 1,"from_range": 6},{"to_range": 17,"discount": 2,"from_range": 12},{"to_range": 23,"discount": 3,"from_range": 18},{"to_range": 29,"discount": 4,"from_range": 24}],"Pricing_Model": "Differential","Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.","Price_Book_Name": "Price_Book_Name oops2"}]);			

示例请求:插入记录


				resp = zoho.crm.bulkCreate("Leads", [{"Last_Name":"Patricia Boyle"},{"Last_Name":"Deborah Grogan"}], {"trigger":["workflow","blueprint","approval"]});			

示例请求:在自定义模块("Students")中创建记录


				resp=zoho.crm.bulkCreate("Students",[{"Name":"Patricia Boyle new","Owner":"7000000031553","Email":"p.boyle@zylker.com","Secondary_Email":"sdf@zylker.com","Single_Line":"Single_Line 22 new","Multi_Line_1":"Room for Negotiation","Currency_1":1.245,"Email_1":"adf@aps.com","Email_Opt_Out":true,"Decimal_1":2.34,"Phone_1":"9000000000","Percent_1":9,"Tag":{"tag"},"Pick_List_1":"new pick list","Long_Integer_1":"123456789012345690","Multi_Select_1":["Val 1","Val 2"],"Checkbox_1":true,"Date_1":"2018-01-31","website":"www.zoho.@","Date_Time_1":"2018-02-01T12:30:00+05:30","Lookup_1":{"id":"7000000032001"},"Number_1":1},{ "Name":"Deborah Grogan","Owner":"7000000031553","Email":"d.grogan@zylker.com","Secondary_Email":"dgrgn@zylker.com","Single_Line":"Single_Line 23 new","Multi_Line_1":"Negotiation succeeded","Currency_1":1.245,"Email_1":"adf@aps.com","Email_Opt_Out":true,"Decimal_1":2.34,"Phone_1":"9000000000","Percent_1":9,"Tag":{"tag"},"Pick_List_1":"new pick list","Long_Integer_1":"123456789012345690","Multi_Select_1":["Val 1","Val 2"],"Checkbox_1":true,"Date_1":"2018-01-31","website":"www.zylker.com","Date_Time_1":"2018-02-01T12:30:00+05:30","Lookup_1":{"id":"7000000032001"},"Number_1":1}]);			

示例输入:


				{
    "data": [
       {
            "Company": "Zylker",
            "Last_Name": "Daly",
            "First_Name": "Paul",
            "Email": "p.daly@zylker.com",
            "State": "Texas"
        },
       {
            "Company": "Villa Margarita",
            "Last_Name": "Dolan",
            "First_Name": "Brian",
            "Email": "brian@villa.com",
            "State": "Texas"
        }
    ],
    "trigger": [
        "approval",
        "workflow",
        "blueprint"
    ]
}			

示例响应


				{
    "data": [
       {
            "message": "record added",
            "details": {
                "created_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "id": "4108880000478027",
                "modified_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "modified_time": "2016-04-28T17:59:21+05:30",
                "created_time": "2016-04-28T17:59:21+05:30"
            },
            "status": "success",
            "code": "SUCCESS"
        },
       {
            "message": "record added",
            "details": {
                "created_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "id": "4108880000478027",
                "modified_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "modified_time": "2016-04-28T17:59:21+05:30",
                "created_time": "2016-04-28T17:59:21+05:30"
            },
            "status": "success",
            "code": "SUCCESS"
        }
    ]
}			

示例请求


				List<ZCRMRecord> records = new List<ZCRMRecord>();
ZCRMUser owner = null;
ZCRMRecord record1 = new ZCRMRecord("Products"); //模块API名称
owner = ZCRMUser.GetInstance(3372164008765466021); // 用户ID
record1.Owner = owner;
record1.SetFieldValue("Product_Name", "mass_create1"); // 字段API名称及其值
ZCRMRecord record2 = new ZCRMRecord("Products"); //模块API名称
owner = ZCRMUser.GetInstance(3372164000008364020); // 用户ID
record2.Owner = owner;
record2.SetFieldValue("Product_Name", "mass_create2"); // 字段API名称及其值
records.Add(record1);
records.Add(record2);
ZCRMModule moduleIns = ZCRMModule.GetInstance("Products"); //模块API名称
BulkAPIResponse<ZCRMRecord> response = moduleIns.CreateRecords(records); //records - 包含创建所需数据的ZCRMRecord实例列表。
List<ZCRMRecord> insertedRecords = response.BulkData; //insertedRecords - ZCRMRecord实例的列表
List<EntityResponse> entityResponses = response.BulkEntitiesResponse; //entityResponse - EntityResponse实例的列表		

示例输入


				{
    "data": [
       {
            "Company": "Zylker",
            "Last_Name": "Daly",
            "First_Name": "Paul",
            "Email": "p.daly@zylker.com",
            "State": "Texas"
        },
       {
            "Company": "Villa Margarita",
            "Last_Name": "Dolan",
            "First_Name": "Brian",
            "Email": "brian@villa.com",
            "State": "Texas"
        }
    ],
    "trigger": [
        "approval",
        "workflow",
        "blueprint"
    ]
}			

示例响应


				{
    "data": [
       {
            "message": "record added",
            "details": {
                "created_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "id": "4108880000478027",
                "modified_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "modified_time": "2016-04-28T17:59:21+05:30",
                "created_time": "2016-04-28T17:59:21+05:30"
            },
            "status": "success",
            "code": "SUCCESS"
        },
       {
            "message": "record added",
            "details": {
                "created_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "id": "4108880000478027",
                "modified_by": {
                    "id": "4108880000086001",
                    "name": "Patricia Boyle"
                },
                "modified_time": "2016-04-28T17:59:21+05:30",
                "created_time": "2016-04-28T17:59:21+05:30"
            },
            "status": "success",
            "code": "SUCCESS"
        }
    ]
}