Magento 2 – 获取购物车示例请求 (GET)

huangapple go评论56阅读模式
英文:

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.

Magento 2 – 获取购物车示例请求 (GET)

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://&lt;host&gt;/rest/V1/integration/customer/token
Content-Type: application/json

{&quot;username&quot;:&quot;&lt;email&gt;&quot;, &quot;password&quot;:&quot;&lt;password&gt;&quot;}

It will return a customer token looks like this:

&quot;3zznrpsthn6m3dheeacyfe3xzdjryd3y&quot;

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:

{
  &quot;id&quot;: 3354,
  &quot;created_at&quot;: &quot;2023-02-15 03:44:37&quot;,
  &quot;updated_at&quot;: &quot;2023-02-15 03:44:37&quot;,
  &quot;is_active&quot;: true,
  &quot;is_virtual&quot;: false,
  &quot;items&quot;: [],
  &quot;items_count&quot;: 0,
  &quot;items_qty&quot;: 0,
  &quot;customer&quot;: {
    &quot;id&quot;: 145,
    &quot;group_id&quot;: 1,
    &quot;default_billing&quot;: &quot;140&quot;,
    &quot;default_shipping&quot;: &quot;140&quot;,
    &quot;created_at&quot;: &quot;2021-09-13 06:47:49&quot;,
    &quot;updated_at&quot;: &quot;2022-10-11 08:03:42&quot;,
    &quot;created_in&quot;: &quot;en_US&quot;,
    &quot;email&quot;: &quot;????&quot;,
    &quot;firstname&quot;: &quot;????&quot;,
    &quot;lastname&quot;: &quot;????&quot;,
    &quot;store_id&quot;: 2,
    &quot;website_id&quot;: 1,
    &quot;addresses&quot;: [
      {
        &quot;id&quot;: 140,
        &quot;customer_id&quot;: 145,
        &quot;region&quot;: {
          &quot;region_code&quot;: &quot;????&quot;,
          &quot;region&quot;: &quot;????&quot;,
          &quot;region_id&quot;: 860
        },
        &quot;region_id&quot;: 860,
        &quot;country_id&quot;: &quot;??&quot;,
        &quot;street&quot;: [
          &quot;???&quot;
        ],
        &quot;telephone&quot;: &quot;????&quot;,
        &quot;city&quot;: &quot;????&quot;,
        &quot;firstname&quot;: &quot;????&quot;,
        &quot;lastname&quot;: &quot;????&quot;,
        &quot;default_shipping&quot;: true,
        &quot;default_billing&quot;: true,
      }
    ],
    &quot;disable_auto_group_change&quot;: 0,
    &quot;extension_attributes&quot;: {
      &quot;is_subscribed&quot;: false
    }
  },
  &quot;billing_address&quot;: {
    &quot;id&quot;: 10058,
    &quot;region&quot;: null,
    &quot;region_id&quot;: null,
    &quot;region_code&quot;: null,
    &quot;country_id&quot;: null,
    &quot;street&quot;: [
      &quot;&quot;
    ],
    &quot;telephone&quot;: null,
    &quot;postcode&quot;: null,
    &quot;city&quot;: null,
    &quot;firstname&quot;: null,
    &quot;lastname&quot;: null,
    &quot;customer_id&quot;: 145,
    &quot;email&quot;: &quot;????&quot;,
    &quot;same_as_billing&quot;: 0,
    &quot;save_in_address_book&quot;: 0
  },
  &quot;orig_order_id&quot;: 0,
  &quot;currency&quot;: {
    &quot;global_currency_code&quot;: &quot;HKD&quot;,
    &quot;base_currency_code&quot;: &quot;HKD&quot;,
    &quot;store_currency_code&quot;: &quot;HKD&quot;,
    &quot;quote_currency_code&quot;: &quot;HKD&quot;,
    &quot;store_to_base_rate&quot;: 0,
    &quot;store_to_quote_rate&quot;: 0,
    &quot;base_to_global_rate&quot;: 1,
    &quot;base_to_quote_rate&quot;: 1
  },
  &quot;customer_is_guest&quot;: false,
  &quot;customer_note_notify&quot;: true,
  &quot;customer_tax_class_id&quot;: 3,
  &quot;store_id&quot;: 1,
  &quot;extension_attributes&quot;: {
    &quot;shipping_assignments&quot;: []
  }
}

huangapple
  • 本文由 发表于 2023年2月27日 17:56:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578962.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定