apisnipcart

Why can I update the e-mail address, but not the billing address?


I followed the doc at this page: https://docs.snipcart.com/v3/sdk/api#cart

I can update the cart like so:

Snipcart.api.cart.update({
  email: 'john.doe@example.com'
}).then(response => {
 console.log("Snipcart.api.cart.update response", response);
}).catch(e => {
 console.log("Snipcart.api.cart.update error", e);
});

However, when I try this:

Snipcart.api.cart.update({
  billingAddress:{
   name: 'John Doe'
 }
}).then(response => {
 console.log("Snipcart.api.cart.update response", response);
}).catch(e => {
 console.log("Snipcart.api.cart.update error", e);
});

I get:

Snipcart.api.cart.update error Object { kind: Getter & Setter, form: Getter & Setter, fields: Getter & Setter, … }

And I can't figure out why !? Any hint?


Solution

  • When updating billing address, you must set all billing address properties, otherwise the validation will fail.

    You can try with:

    Snipcart.api.cart.update({
      email: "johndoe@company.com",
      billingAddress:{
       ...address,
       name: 'John Doe'
     }
    }).then(response => {
     console.log("Snipcart.api.cart.update response", response);
    }).catch(e => {
     console.log("Snipcart.api.cart.update error", e);
    });