在与woocommerce商店连接时缺少离子3中的参数

问题描述 投票:0回答:4

代码是:

signup(){

      let customerData = {

        customer : {}
      }

      customerData.customer = {
        "email": this.newUser.email,
        "first_name": this.newUser.first_name,
        "last_name": this.newUser.last_name,
        "username": this.newUser.username,
        "password": this.newUser.password,
        "billing_address": {
          "first_name": this.newUser.first_name,
          "last_name": this.newUser.last_name,
          "company": "",
          "address_1": this.newUser.billing_address.address_1,
          "address_2": this.newUser.billing_address.address_2,
          "city": this.newUser.billing_address.city,
          "state": this.newUser.billing_address.state,
          "postcode": this.newUser.billing_address.postcode,
          "country": this.newUser.billing_address.country,
          "email": this.newUser.email,
          "phone": this.newUser.billing_address.phone
        },
        "shipping_address": {
          "first_name": this.newUser.first_name,
          "last_name": this.newUser.last_name,
          "company": "",
          "address_1": this.newUser.shipping_address.address_1,
          "address_2": this.newUser.shipping_address.address_2,
          "city": this.newUser.shipping_address.city,
          "state": this.newUser.shipping_address.state,
          "postcode": this.newUser.shipping_address.postcode,
          "country": this.newUser.shipping_address.country
        }
      }

      if(this.billing_shipping_same){
        this.newUser.shipping_address = this.newUser.shipping_address;
      }

      this.WooCommerce.postAsync('customers',customerData).then( (data) => {

        let response = (JSON.parse(data.body)); 
}
}/ignore the parentheses 

运行此代码我收到此错误,我无法修复:

{code: "rest_missing_callback_param", message: "Missing parameter(s): email, password",…}
code
:
"rest_missing_callback_param"
data
:
{status: 400, params: ["email", "password"]}
params
:
["email", "password"]
status
:
400
message
:
"Missing parameter(s): email, password"
angular ionic3 woocommerce-rest-api
4个回答
0
投票

在数据对象中,正确发送电子邮件和密码:

data: { params: { email: <email here>, password: <password here> } }

0
投票
this.Woocommerce.postAsync('customers',customerData.customer).then((data) => {
  console.log (JSON.parse(data.body));
})

0
投票

问题在于您的托管网站支持的帖子功能。通常托管站点强制执行帖子的安全性,因为有时帖子的主体没有通过。您最好在数字海洋,AWS或GCP下创建自己的托管服务器,并按照以下步骤创建wordpress安装。安装wordpress后,添加woocommerce插件并使用chrome CORS插件启用CORS。

https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lamp-on-ubuntu-16-04


0
投票

抱歉一周英语,但我也面临同样的问题。我在config.ts文件和service.ts文件中进行了更改。

最后,它工作正常

错误:{“code”:“rest_missing_callback_param”,“message”:“缺少参数:电子邮件,密码”,“数据”:{“status”:400,“params”:[“email”,“password” ]}}

我改变了config.ts中的标题

headers.append('Content-Type','application / json');

并在service.ts文件中执行一些更改

registerCustomer(customer){var params = {customer:customer,email:customer.email,password:customer.password,};返回新的Promise(resolve => { this.http.post(this.config.setUrl('POST','/ wp-json / wc / v1 / customers?',false),params,this.config.options).map(res => res.json ())。subscribe(data => {this.user = data; resolve(this.user);},err => {resolve(err.json())}); }); }

- - 要么 - - -

使用此代码

var options:any = {};

registerCustomer(customer) {
    var params = {
        customer: customer,
        email: customer.email,
        password: customer.password,
    };
    var headers = new Headers();
        headers.append('Content-Type', 'application/json');
    this.options.withCredentials = true;
    this.options.headers = headers;
    return new Promise(resolve => {
        this.http.post(this.config.setUrl('POST', '/wp-json/wc/v1/customers?', false), params, this.options).map(res => res.json()).subscribe(data => {

            this.user = data;
            resolve(this.user);
        }, err => {
            alert("You are already registered with this email id !!");
            resolve(err.json())
        });
    });
}
© www.soinside.com 2019 - 2024. All rights reserved.