Answers.Body: <p>Stumbled over the old questions, this is how it works:</p>
  
  <pre><code>updateShipping() {
          const options = {
              method: 'post',
              url: '/actions/commerce/cart/update-cart',
              headers: {
                  'X-CSRF-Token': window.Craft.csrfToken,
              },
              data: qs.stringify({
                  shippingMethodHandle: 'standardShipping',
                  shippingSameAsBilling: 0,
                  shippingAddressId: 123, // remove if it doesn't exists or is new
                  shippingAddress: {
                     id: '', // only needed if address is new
                     firstName: 'test',
                     ...
                  },
              }),
          };
          axios(options)
              .then(response =&gt; {...})
              .catch(error =&gt; {...});
      },
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-27T06:03:45.850Z
Answers.LastActivityDate: 2019-06-27T06:03:45.850Z
Answers.UserDisplayName: HendrikEng
Body: <p>I am trying to change/set a customers shippingAddress via <code>axios</code></p>
  
  <p>It does work e.g. for setting the <code>shippingMethod</code> or the quantity for a product. However if i want to set a new <code>shippingAddress</code> the <code>axios post</code> fails with a <code>500 status</code></p>
  
  <p>This is my axios post request:</p>
  
  <pre><code>updateShipping() {
          const options = {
              method: 'POST',
              headers: {
                  'content-type': 'application/x-www-form-urlencoded',
                  'X-CSRF-Token': window.Craft.csrfToken,
              },
              data: qs.stringify({
                  shippingMethodHandle: 'standardShipping', //works
                  shippingSameAsBilling: false, // wont work
                  shippingAddressId: 'new', // wont work, also tried an existing
                  shippingAddress: {
                     firstName: 'test',
                     ...
                  },
              }),
              url: '/actions/commerce/cart/update-cart',
          };
          axios(options)
              .then(response =&gt; {...})
              .catch(error =&gt; {...});
      },
  </code></pre>
  
Tags: <craft3><javascript><plugin-craftcommerce2>
Title: Setting a new / override shippingAddress via axios
ThreadText: # Setting a new / override shippingAddress via axios
  
  (Asked by: username_0 on 2018-11-23)
  
  I am trying to change/set a customers shippingAddress via `axios`
  
  It does work e.g. for setting the `shippingMethod` or the quantity for a product. However if i want to set a new `shippingAddress` the `axios post` fails with a `500 status`
  
  This is my axios post request:
  
  ```
  updateShipping() {
          const options = {
              method: 'POST',
              headers: {
                  'content-type': 'application/x-www-form-urlencoded',
                  'X-CSRF-Token': window.Craft.csrfToken,
              },
              data: qs.stringify({
                  shippingMethodHandle: 'standardShipping', //works
                  shippingSameAsBilling: false, // wont work
                  shippingAddressId: 'new', // wont work, also tried an existing
                  shippingAddress: {
                     firstName: 'test',
                     ...
                  },
              }),
              url: '/actions/commerce/cart/update-cart',
          };
          axios(options)
              .then(response => {...})
              .catch(error => {...});
      },
  
  ```
  
  **Tags:** craft3, javascript, plugin-craftcommerce2
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-06-27. Score: 1 | Accepted answer
  
  Stumbled over the old questions, this is how it works:
  
  ```
  updateShipping() {
          const options = {
              method: 'post',
              url: '/actions/commerce/cart/update-cart',
              headers: {
                  'X-CSRF-Token': window.Craft.csrfToken,
              },
              data: qs.stringify({
                  shippingMethodHandle: 'standardShipping',
                  shippingSameAsBilling: 0,
                  shippingAddressId: 123, // remove if it doesn't exists or is new
                  shippingAddress: {
                     id: '', // only needed if address is new
                     firstName: 'test',
                     ...
                  },
              }),
          };
          axios(options)
              .then(response => {...})
              .catch(error => {...});
      },
  
  ```
  
  
  ---
  
  