简体   繁体   English

Etsy in Angular:将产品添加到访客购物车

[英]Etsy in Angular: Adding products to guest cart

I'm trying to add products to my guest cart, passing the guest_id in the url and the listings_id in the body. 我正在尝试将产品添加到我的客户购物车中,在URL中传递guest_id并在正文中传递listings_id。 This is the method: 这是方法:

addToGuestCart(){
    this.http.post(`https://openapi.etsy.com/v2/guests/${this.guest.guest_id}/carts?api_key=my-api-key`, this.product.listing_id)
      .first()
      .subscribe(()=>this.getGuest());
  }

I get this cors error: 我收到这个错误提示:

XMLHttpRequest cannot load https://openapi.etsy.com/v2/guests/akye30nuit6ua/carts?api_key=my-api-key . XMLHttpRequest无法加载https://openapi.etsy.com/v2/guests/akye30nuit6ua/carts?api_key=my-api-key No 'Access-Control-Allow-Origin' header is present on the requested resource. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin ' http://localhost:4200 ' is therefore not allowed access. 因此,不允许访问源' http:// localhost:4200 '。 The response had HTTP status code 500. 响应的HTTP状态码为500。

Input of HTTP POST body is object so you should use : { listing_id: this.product.listing_id } HTTP POST正文的输入是object,因此您应该使用: { listing_id: this.product.listing_id }

I read in https://www.etsy.com/developers/documentation/reference/guestcart , I think you should send [listing_id] via url as : 我在https://www.etsy.com/developers/documentation/reference/guestcart中阅读,我认为您应该通过url发送[listing_id]为:

/guests/:guest_id/carts?api_key=my-api-key&listing_id=listing_id_value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM