英文:
Magento 2 - Request sample for carts/mine (GET)
问题
尝试调用Magento 2 REST API的carts/mine
GET路由,但在文档中没有显示请求示例。
它说:“返回指定客户的购物车信息。”
但我如何指定客户?
英文:
I try to call the carts/mine GET route of the Magento 2 REST API, but it does not show a request sample in the documentation.
It says "Returns information for the cart for a specified customer."
But how do I specify the customer?
答案1
得分: 1
以下是翻译好的部分:
-
You should include a customer bearer to call this API.
你应该包括一个客户令牌以调用此 API。 -
You can get it from calling
/integration/customer/token
.
你可以通过调用/integration/customer/token
获取它。 -
Here is an example:
这是一个示例: -
POST https://<host>/rest/V1/integration/customer/token
POST https://<host>/rest/V1/integration/customer/token -
Content-Type: application/json
Content-Type: application/json -
{"username":"<email>", "password":"<password>"}
{"username":"<email>", "password":"<password>"} -
It will return a customer token looks like this:
它将返回一个类似于这样的客户令牌: -
"3zznrpsthn6m3dheeacyfe3xzdjryd3y"
"3zznrpsthn6m3dheeacyfe3xzdjryd3y" -
Then use this bearer token to call
cart/mine
API:
然后使用此令牌来调用cart/mine
API: -
GET {{host}}/rest/V1/carts/mine/
GET {{host}}/rest/V1/carts/mine/ -
Authorization: Bearer 3zznrpsthn6m3dheeacyfe3xzdjryd3y
Authorization: Bearer 3zznrpsthn6m3dheeacyfe3xzdjryd3y -
Content-Type: application/json
Content-Type: application/json -
And this is an example response:
这是一个示例响应: -
{"id": 3354,
{"id": 3354, -
"created_at": "2023-02-15 03:44:37",
"created_at": "2023-02-15 03:44:37", -
"updated_at": "2023-02-15 03:44:37",
"updated_at": "2023-02-15 03:44:37", -
"is_active": true,
"is_active": true, -
"is_virtual": false,
"is_virtual": false, -
"items": [],
"items": [], -
"items_count": 0,
"items_count": 0, -
"items_qty": 0,
"items_qty": 0, -
"customer": {
"customer": { -
"id": 145,
"id": 145, -
"group_id": 1,
"group_id": 1, -
"default_billing": "140",
"default_billing": "140", -
"default_shipping": "140",
"default_shipping": "140", -
"created_at": "2021-09-13 06:47:49",
"created_at": "2021-09-13 06:47:49", -
"updated_at": "2022-10-11 08:03:42",
"updated_at": "2022-10-11 08:03:42", -
"created_in": "en_US",
"created_in": "en_US", -
"email": "????",
"email": "????", -
"firstname": "????",
"firstname": "????", -
"lastname": "????",
"lastname": "????", -
"store_id": 2,
"store_id": 2, -
"website_id": 1,
"website_id": 1, -
"addresses": [
"addresses": [ -
{
{ -
"id": 140,
"id": 140, -
"customer_id": 145,
"customer_id": 145, -
"region": {
"region": { -
"region_code": "????",
"region_code": "????", -
"region": "????",
"region": "????", -
"region_id": 860
"region_id": 860 -
"region_id": 860,
"region_id": 860, -
"country_id": "??",
"country_id": "??", -
"street": [
"street": [ -
"???"
"???" -
],
], -
"telephone": "????",
"telephone": "????", -
"city": "????",
"city": "????", -
"firstname": "????",
"firstname": "????", -
"lastname": "????",
"lastname": "????", -
"default_shipping": true,
"default_shipping": true, -
"default_billing": true,
"default
英文:
You should include a customer bearer to call this API. You can get it from calling /integration/customer/token
. Here is an example:
POST https://<host>/rest/V1/integration/customer/token
Content-Type: application/json
{"username":"<email>", "password":"<password>"}
It will return a customer token looks like this:
"3zznrpsthn6m3dheeacyfe3xzdjryd3y"
Then use this bearer token to call cart/mine
API:
GET {{host}}/rest/V1/carts/mine/
Authorization: Bearer 3zznrpsthn6m3dheeacyfe3xzdjryd3y
Content-Type: application/json
And this is an example response:
{
"id": 3354,
"created_at": "2023-02-15 03:44:37",
"updated_at": "2023-02-15 03:44:37",
"is_active": true,
"is_virtual": false,
"items": [],
"items_count": 0,
"items_qty": 0,
"customer": {
"id": 145,
"group_id": 1,
"default_billing": "140",
"default_shipping": "140",
"created_at": "2021-09-13 06:47:49",
"updated_at": "2022-10-11 08:03:42",
"created_in": "en_US",
"email": "????",
"firstname": "????",
"lastname": "????",
"store_id": 2,
"website_id": 1,
"addresses": [
{
"id": 140,
"customer_id": 145,
"region": {
"region_code": "????",
"region": "????",
"region_id": 860
},
"region_id": 860,
"country_id": "??",
"street": [
"???"
],
"telephone": "????",
"city": "????",
"firstname": "????",
"lastname": "????",
"default_shipping": true,
"default_billing": true,
}
],
"disable_auto_group_change": 0,
"extension_attributes": {
"is_subscribed": false
}
},
"billing_address": {
"id": 10058,
"region": null,
"region_id": null,
"region_code": null,
"country_id": null,
"street": [
""
],
"telephone": null,
"postcode": null,
"city": null,
"firstname": null,
"lastname": null,
"customer_id": 145,
"email": "????",
"same_as_billing": 0,
"save_in_address_book": 0
},
"orig_order_id": 0,
"currency": {
"global_currency_code": "HKD",
"base_currency_code": "HKD",
"store_currency_code": "HKD",
"quote_currency_code": "HKD",
"store_to_base_rate": 0,
"store_to_quote_rate": 0,
"base_to_global_rate": 1,
"base_to_quote_rate": 1
},
"customer_is_guest": false,
"customer_note_notify": true,
"customer_tax_class_id": 3,
"store_id": 1,
"extension_attributes": {
"shipping_assignments": []
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论