操作文档类型

文档类型(DocType)是一种特定类型的文档,例如:客户、员工或物料。

文档名称(DocumentName)是文档的唯一标识符,例如:CUST-00001、EMP-00001 或 ITEM-00001。

以下示例中缺少身份验证。更多信息请参阅[基本身份验证]和[OAuth2]。

GET /api/resource/{DocType}

获取该文档类型下的文档列表。

路径参数:

  • DocType(字符串)

你想要获取的文档类型。例如:’Customer’。

查询参数:

  • fields []

默认情况下,只返回 ‘name’ 字段。要添加更多字段,可以传入 fields 参数。例如:fields=[“name”,”country”]

  • filters [[(string)]]

你可以通过在 filters 参数中传入 SQL 条件来筛选列表。每个条件的格式为 [{doctype}, {field}, {operator}, {value}]。例如:filters=[[“Customer”, “country”, “=”, “India”]]

  • limit_page_length(整数)

所有列表都会分页显示。通过此参数可以更改页面大小(一次返回多少条记录)。默认值:20。

  • limit_start(整数)

要请求后续页面,请传入 limit_page_length 的倍数作为 limit_start。例如,要请求第二页,请将 limit_start 设为 20。

示例:

获取所有电话号码为 4915227058038 的客户的最多 20 个名称(ID)。

curl -X GET https://{your frappe instance}/api/resource/Customer?fields=["name"]\
 &filters=[["Customer","phone","=","4915227058038"]]

返回值:

 {
 "data": [
 {
 "name": "CUST-00001"
 },
 ]
 }

POST /api/resource/{DocType}

创建该文档类型的新文档。

路径参数:

  • DocType(字符串)

你想要创建的文档类型。例如:’Customer’。

Content-Type:application/json

请求体:{"fieldname": value}

示例:

创建一个名为 Mustermann 的新线索。

curl -X POST https://{your frappe instance}/api/resource/Lead \
 -H 'Content-Type: application/json' \
 -H 'Accept: application/json' \
 -d '{"lead_name":"Mustermann"}'

GET /api/resource/{DocType}/{DocumentName}

按名称(ID)获取特定文档。

路径参数:

  • DocType(字符串)

你想要获取的文档类型。例如:’Customer’。

  • DocumentName(字符串)

你想要获取的文档名称(ID)。例如:’EMP-00001’。

示例:

获取名称为(ID)CUST-00001 的客户。

curl -X GET https://{your frappe instance}/api/resource/Customer/CUST-00001

PUT /api/resource/{DocType}/{DocumentName}

更新特定文档。这类似于 PATCH HTTP 请求,你不需要发送整个文档,只需发送要更改的部分。

路径参数:

  • DocType(字符串)

你想要更新的文档类型。例如:’Customer’。

  • DocumentName(字符串)

你想要更新的文档名称(ID)。例如:’EMP-00001’。

Content-Type:application/json

请求体:{"fieldname": value}

示例:

更新下次联系日期。

curl -X PUT https://{your frappe instance}/api/resource/Lead/LEAD-00001 \
 -H 'Accept: application/json' \
 -H 'Content-Type: application/json' \
 -d '{"contact_date":"2018-10-08"}'

返回值:

{
 "data": {
 "doctype": "Lead",
 "name": "LEAD-00001",
 "contact_date": "2018-10-08",
 "...": "..."
 }
}

DELETE /api/resource/{DocType}/{DocumentName}

路径参数:

  • DocType(字符串)

你想要删除的文档类型。例如:’Customer’。

  • DocumentName(字符串)

你想要删除的文档名称(ID)。例如:’EMP-00001’。

延伸阅读

HTTP 请求头:

  • Content-Type
  • Accept
  • Authorization

作者:Raffael Meyer([email protected])