仅“已办理”状态的订单可以删除,已经入仓过的订单无法通过该接口取消。
请求内容格式为 JSON (Content-Type: application/json) 字符编码 UTF-8.
为了取消订单需要发送 DELETE-请求, 请求URL:
测试环境 | https://api.edu.cdek.ru/v2/orders/{uuid} |
---|---|
正式环境 | https://api.cdek.ru/v2/orders/{uuid} |
中国的环境 | https://int.cdek-express.cn/v2/orders/{uuid} |
返回的内容
返回的内容为 JSON 格式:
序号 | 属性 | 名称 | 属性类型 | 必填的 |
---|---|---|---|---|
1 | entity | 订单信息 | entity | 否 |
1.1 | uuid | CDEK订单识别码 | UUID | 否 |
2 | requests | 订单对应的请求列表 | request[] | 是 |
2.1 | request_uuid | 请求识别码(uuid) | UUID | 否 |
2.2 | type | 请求类型,所可能的类型:CREATE, UPDATE, DELETE, AUTH, GET | string() | 是 |
2.3 | date_time | 状态日期 (格式为:yyyy-MM-dd’T’HH:mm:ssZ) | datetime | 是 |
2.4 | state | 目前的状态 所可能的状态: ACCEPTED, WAITING, SUCCESSFUL, INVALID |
string() | 是 |
2.5 | errors | 进行请求中发生的错误列表 | error[] | 否 |
2.5.1 | code | 错误编码 | string() | 是 |
2.5.2 | message | 错误描述 | string() | 是 |
2.6 | warnings | 警告列表 | warning[] | 否 |
2.6.1 | code | 警告编码 | string() | 是 |
2.6.2 | message | 警告描述 | string() | 是 |
请求例子:
# encoding: utf-8
import requests
import urllib.parse
import sys
entity_uuid = '72753033-db0e-4042-9392-c5a077e24669'
access_token = "....." #- 访问令牌
url = f'https://api.cdek.ru/v2/orders/{entity_uuid}'
headers = {'Authorization': 'Bearer '+access_token, 'Content-type': 'application/json'}
responce = requests.delete(url, headers=headers)
print(responce) # <Response [200]>
print(responce.text)
返回的数据
{
"entity": {
"uuid": "72753033-db0e-4042-9392-c5a077e24669"
},
"requests": [{
"request_uuid": "72753033-fafa-46a5-81a4-c7dab856a408",
"type": "DELETE",
"date_time": "2020-03-27T17:26:10+0700",
"state": "ACCEPTED"
}]
}
申请删除之后可以获取订单状态:
responce = requests.get(f'https://api.cdek.ru/v2/orders/{entity_uuid}', headers=headers)
print(responce.text)
print(responce)
{
"entity": {
"uuid": "72753033-35da-44aa-8eb0-005f09dec68a",
"type": 1,
"is_return": false,
"cdek_number": "1169343879",
"number": "TEST7-CT789435359CN",
"tariff_code": 246,
"comment": "",
"date_invoice": "2020-03-26",
"shipper_name": "CDEK",
"shipper_address": "Novosibirsk",
"delivery_recipient_cost": {
"value": 0
},
"sender": {
"name": "Zhang san"
},
"seller": {
"name": "Zhang san",
"address": "Shanghai, Changning District"
},
"recipient": {
"name": "Ivanov Sergei Petrovich",
"phones": [{
"number": "9990003456"
}, {
"number": "9990001234"
}]
},
"from_location": {
"code": "12683",
"postal_code": "200050",
"longitude": 121.470462,
"latitude": 31.230863,
"country_code": "CN",
"region": "Шанхай",
"region_code": "906",
"sub_region": "",
"city": "Шанхай",
"address": "",
"country": "Китай (КНР)"
},
"to_location": {
"code": "430",
"fias_guid": "bb035cc3-1dc2-4627-9d25-a1bf2d4b936b",
"postal_code": "443034",
"longitude": 50.1018,
"latitude": 53.1955,
"country_code": "RU",
"region": "Самарская",
"region_code": "57",
"sub_region": "Самара",
"city": "Самара",
"kladr_code": "6300000100000",
"address": "Lenina ulitsa, 35 28;Samara;Samarskaya oblast",
"country": "Россия"
},
"packages": [{
"number": "TEST7-CT789435359CN",
"weight": 120,
"length": 0,
"width": 0,
"height": 0,
"comment": "приложена опись",
"items": [{
"name": "Measuring tools",
"ware_key": "WELRV0086000627YQ",
"payment": {
"value": 0
},
"weight": 120,
"weight_gross": 120,
"amount": 1,
"url": "",
"cost": 0
}, {
"name": "Measuring tools",
"ware_key": "WELRV0086000627YQ",
"payment": {
"value": 0.0,
"vat_sum": 0.0
},
"weight": 120,
"weight_gross": 120,
"amount": 1,
"cost": 0.0
}]
}],
"statuses": [{
"code": "ACCEPTED",
"name": "Принят",
"date_time": "2020-03-27T17:34:42+0700",
"city": "Офис СДЭК"
}, {
"code": "CREATED",
"name": "Создан",
"date_time": "2020-03-27T17:34:43+0700",
"city": "Офис СДЭК"
}, {
"code": "CREATED",
"name": "Создан",
"date_time": "2020-03-27T17:34:44+0700",
"city": "Шанхай"
}, {
"code": "REMOVED",
"name": "Удален",
"date_time": "2020-03-27T17:38:46+0700",
"city": "Офис СДЭК"
}],
"shop_seller_name": "Zhang san",
"shop_seller_address": "Shanghai, Changning District"
},
"requests": [{
"request_uuid": "72753033-6f26-4cbc-9daf-7d44f04e50f9",
"type": "CREATE",
"date_time": "2020-03-27T17:34:43+0700",
"state": "SUCCESSFUL" //CREATE SUCCESSFUL 成功下单了
}, {
"request_uuid": "72753033-d0aa-4c65-a20e-ebe3970ba368",
"type": "DELETE",
"date_time": "2020-03-27T17:38:47+0700",
"state": "SUCCESSFUL" //type DELETE SUCCESSFUL订单已经成功被删除了
}]
}