magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.5k stars 9.3k forks source link

GET /V1/carts/mine/items is returning "cartId is a required field" #1443

Closed sauberia closed 9 years ago

sauberia commented 9 years ago

The webapi.xml for Quote specifies the getList method but I believe this should be getListForCustomer instead.

    <route url="/V1/carts/mine/items" method="GET">
        <service class="Magento\Quote\Api\CartItemRepositoryInterface" method="getList"/>
        <resources>
            <resource ref="self" />
        </resources>
        <data>
            <parameter name="customerId" force="true">%customer_id%</parameter>
        </data>
    </route>

Likewise, PUT /V1/carts/mine/items/:itemId should use saveForCustomer and DELETE /V1/carts/mine/items/:itemId should use deleteByIdForCustomer.


Here is a ruby hash of the the request and response:

{
            :method => :get,
              :body => "{\"message\":\"%fieldName is a required field.\",\"parameters\":{\"fieldName\":\"cartId\"}}",
               :url => #<URI::HTTP http://localhost/magento2/rest/V1/carts/mine/items>,
           :request => {
    :params_encoder => nil,
             :proxy => nil,
              :bind => nil,
           :timeout => nil,
      :open_timeout => nil,
          :boundary => nil,
             :oauth => nil
  },
   :request_headers => {
       "User-Agent" => "Faraday v0.9.1",
    "Authorization" => "Bearer e9txps1sw6mrv1qf48ihrrx9rtku3uj2",
     "Content-Type" => "application/json"
  },
               :ssl => {
          :verify => nil,
         :ca_file => nil,
         :ca_path => nil,
     :verify_mode => nil,
      :cert_store => nil,
     :client_cert => nil,
      :client_key => nil,
     :certificate => nil,
     :private_key => nil,
    :verify_depth => nil,
         :version => nil
  },
  :response_headers => {
              "date" => "Sun, 05 Jul 2015 16:31:00 GMT",
            "server" => "Apache/2.2.26 (Unix) DAV/2 PHP/5.6.10 mod_ssl/2.2.26 OpenSSL/0.9.8za",
      "x-powered-by" => "PHP/5.6.10",
        "set-cookie" => "PHPSESSID=ou53q01g0kvemeq6dm1ho2r7b0; expires=Sun, 05-Jul-2015 17:31:01 GMT; Max-Age=3600; path=/magento2; domain=localhost; HttpOnly",
           "expires" => "Thu, 19 Nov 1981 08:52:00 GMT",
     "cache-control" => "no-store, no-cache, must-revalidate, post-check=0, pre-check=0",
            "pragma" => "no-cache",
    "content-length" => "81",
        "connection" => "close",
      "content-type" => "application/json; charset=utf-8"
  },
            :status => 400
}
sauberia commented 9 years ago

Just to demonstrate that the web API token authorisation is working, here is a request for the authenticated customer's cart:

{
            :method => :get,
              :body => "{\"id\":1,\"created_at\":\"2015-07-05 17:30:40\",\"updated_at\":\"0000-00-00 00:00:00\",\"is_active\":true,\"is_virtual\":false,\"items_count\":0,\"items_qty\":0,\"customer\":{\"id\":1,\"group_id\":1,\"created_at\":\"2015-07-05 16:29:15\",\"created_in\":\"Default Store View\",\"email\":\"marc@marctauber.com\",\"firstname\":\"Marc\",\"lastname\":\"Tauber\",\"store_id\":1,\"website_id\":1,\"addresses\":[],\"disable_auto_group_change\":0},\"checkout_method\":\"login_in\",\"shipping_address\":{\"region\":null,\"region_id\":null,\"region_code\":null,\"country_id\":null,\"street\":[\"\"],\"telephone\":null,\"postcode\":null,\"city\":null,\"firstname\":null,\"lastname\":null,\"email\":\"marc@marctauber.com\"},\"billing_address\":{\"region\":null,\"region_id\":null,\"region_code\":null,\"country_id\":null,\"street\":[\"\"],\"telephone\":null,\"postcode\":null,\"city\":null,\"firstname\":null,\"lastname\":null,\"email\":\"marc@marctauber.com\"},\"orig_order_id\":0,\"currency\":{\"global_currency_code\":\"GBP\",\"base_currency_code\":\"GBP\",\"store_currency_code\":\"GBP\",\"quote_currency_code\":\"GBP\",\"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}",
               :url => #<URI::HTTP http://localhost/magento2/rest/V1/carts/mine>,
           :request => {
    :params_encoder => nil,
             :proxy => nil,
              :bind => nil,
           :timeout => nil,
      :open_timeout => nil,
          :boundary => nil,
             :oauth => nil
  },
   :request_headers => {
       "User-Agent" => "Faraday v0.9.1",
    "Authorization" => "Bearer e9txps1sw6mrv1qf48ihrrx9rtku3uj2",
     "Content-Type" => "application/json"
  },
               :ssl => {
          :verify => nil,
         :ca_file => nil,
         :ca_path => nil,
     :verify_mode => nil,
      :cert_store => nil,
     :client_cert => nil,
      :client_key => nil,
     :certificate => nil,
     :private_key => nil,
    :verify_depth => nil,
         :version => nil
  },
  :response_headers => {
              "date" => "Sun, 05 Jul 2015 16:52:24 GMT",
            "server" => "Apache/2.2.26 (Unix) DAV/2 PHP/5.6.10 mod_ssl/2.2.26 OpenSSL/0.9.8za",
      "x-powered-by" => "PHP/5.6.10",
        "set-cookie" => "PHPSESSID=a0mbekqfjqnbpd89o0vq6k0hm4; expires=Sun, 05-Jul-2015 17:52:24 GMT; Max-Age=3600; path=/magento2; domain=localhost; HttpOnly",
           "expires" => "Thu, 19 Nov 1981 08:52:00 GMT",
     "cache-control" => "no-store, no-cache, must-revalidate, post-check=0, pre-check=0",
            "pragma" => "no-cache",
    "content-length" => "1168",
        "connection" => "close",
      "content-type" => "application/json; charset=utf-8"
  },
            :status => 200
}
vpelipenko commented 9 years ago

Internal ticket: MAGETWO-39766

vpelipenko commented 9 years ago

@sauberia, issue is fixed and available in develop branch. Please, check the fix and let us know if it doesn't work for you.

thdoan commented 7 years ago

I just encountered this issue in Magento 2.1.5 when checking out as a registered user with a saved address. It is preventing the user from selecting a shipping method. I have traced the error to a 400 Bad Request...

Request URL = .../rest/us/V1/carts/mine/estimate-shipping-methods-by-address-id Request Payload = {addressId: "60"} Response:

{"message":"%fieldName is a required field.","parameters":{"fieldName":"cartId"},"trace":"#0 \/path\/to\/docroot\/vendor\/magento\/framework\/Webapi\/ServiceInputProcessor.php(131): Magento\\Framework\\Webapi\\ServiceInputProcessor->processInputError(Array)\n#1 \/path\/to\/docroot\/vendor\/magento\/module-webapi\/Controller\/Rest\/InputParamsResolver.php(101): Magento\\Framework\\Webapi\\ServiceInputProcessor->process('Magento\\\\Quote\\\\A...', 'estimateByAddre...', Array)\n#2 \/path\/to\/docroot\/vendor\/magento\/module-webapi\/Controller\/Rest.php(299): Magento\\Webapi\\Controller\\Rest\\InputParamsResolver->resolve()\n#3 \/path\/to\/docroot\/vendor\/magento\/module-webapi\/Controller\/Rest.php(216): Magento\\Webapi\\Controller\\Rest->processApiRequest()\n#4 \/path\/to\/docroot\/vendor\/magento\/framework\/Interception\/Interceptor.php(146): Magento\\Webapi\\Controller\\Rest->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#5 \/path\/to\/docroot\/var\/generation\/Magento\/Webapi\/Controller\/Rest\/Interceptor.php(39): Magento\\Webapi\\Controller\\Rest\\Interceptor->___callPlugins('dispatch', Array, Array)\n#6 \/path\/to\/docroot\/vendor\/magento\/framework\/App\/Http.php(135): Magento\\Webapi\\Controller\\Rest\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#7 \/path\/to\/docroot\/vendor\/magento\/framework\/App\/Bootstrap.php(258): Magento\\Framework\\App\\Http->launch()\n#8 \/path\/to\/docroot\/index.php(52): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http))\n#9 {main}"}
wrock commented 7 years ago

I also encounter this issue eventually on Magento 2.1.3

sydekumf commented 7 years ago

I have the same error and debugged it. In the end there is something else wrong which I described here: https://github.com/magento/magento2/issues/9744 It is because Magento hides the exception...

MikeSheward commented 7 years ago

I'm also getting this error, probably from https://github.com/magento/magento2/issues/9744, any ideas how to resolve this?