Attachments 附件接口

JSON 格式

NameTypeRead-onlyComment
idintegeryes附件id,由系统自动分配
urlstringyes资源url
namestringyes附件名称
sizeintegeryes附件大小
content_urlstringyes附件获取地址,即下载地址
tokenstringyes附件的token,凭借token可以将附件绑定到工单回复等资源

JSON 示例

{
	"id": 1948,
	"url": "https://support.kf5.com/apiv2/attachments/1948.json",
	"name": "hello.gif",
	"size": 8238,
	"content_url": "https://support.kf5.com/attachments/download/1948/00154af5872418a7792dda0edb32921/",
	"token": "00154af5872418a7792dda0edb32921"
}

上传附件

POST /apiv2/attachments.json

注意:需要在url里添加filename参数来设置附件文件名

同一个附件只能对应一个工单或一个工单回复或一个文档

请求header里需要设置"Content-Type: application/binary"

POST /apiv2/attachments.json?filename=test.jpg
curl 示例
curl -u {email_address}:{password} -H "Content-Type: application/binary" \
   --data-binary @hello.gif -X POST \
   https://{subdomain}.kf5.com/apiv2/attachments.json?filename=hello.gif
返回示例
Status: 201 Created
Location: https://{subdomain}.kf5.com/apiv2/attachments/{id}.json

{
	"attachment": {
		"id": 1948,
		"url": "https://support.kf5.com/apiv2/attachments/1948.json",
		"name": "hello.gif",
		"size": 8238,
		"content_url": "https://support.kf5.com/attachments/download/1948/00154af5872418a7792dda0edb32921/",
		"token": "00154af5872418a7792dda0edb32921"
	}
}

注意:上传附件,成功返回数据后,在提交工单的时候只需要将token值附带到uploads后面即可。

附带附件的创建工单示例
curl https://{subdomain}.kf5.com/apiv2/requests.json \
  -d '{"request": {"title": "Help!", "comment": {"content": "My new requests", "uploads": ["00156a9d6e82efefcbbd874ffbf617e","00156a9d6e82efefcbbd874ffbf617e"]}}}' \
  -v -u {email_address}/token:{api_token} -X POST -H "Content-Type: application/json"

查看附件

GET /apiv2/attachments/{id}.json

调用权限:agent

curl 示例
curl -u {email_address}:{password} \
   https://{subdomain}.kf5.com/apiv2/attachments/{id}.json
返回示例
Status: 200 OK

{
	"attachment": {
		"id": 1948,
		"url": "https://support.kf5.com/apiv2/attachments/1948.json",
		"name": "hello.gif",
		"size": 8238,
		"content_url": "https://support.kf5.com/attachments/download/1948/00154af5872418a7792dda0edb32921/",
		"token": "00154af5872418a7792dda0edb32921"
	}
}

删除附件

DELETE /apiv2/attachments/{id}.json
调用权限

agent

curl 示例
curl -u {email_address}:{password} -X DELETE \
   https://{subdomain}.kf5.com/apiv2/attachments/{id}.json
返回示例
Status: 200 OK