首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Magento 2注册和登录REST

Magento 2注册和登录REST
EN

Stack Overflow用户
提问于 2020-04-18 12:50:22
回答 1查看 3.4K关注 0票数 0

我正在用Rest为magento2创建一个应用程序。我面临以下问题。

我可以通过REST创建用户

代码语言:javascript
复制
auth Berear token : bbiotqwwj04prtja2oum5gvfsqt8dnjh

API : Register 

URL : http://demo-acm-2.bird.eu/rest/all/V1/customers
method : POST
Request Body 

  {
     "customer": {
         "email": "pradeep123@gmail.com",
         "firstname": "Abc",
         "lastname": "Xyz",
         "storeId": 1
     },
     "password": "Qwe@123123"
  }


Response 

{
    "id": 3,
    "group_id": 1,
    "created_at": "2020-04-18 12:30:40",
    "updated_at": "2020-04-18 12:30:40",
    "created_in": "Default Store View",
    "email": "pradeep123@gmail.com",
    "firstname": "Abc",
    "lastname": "Xyz",
    "store_id": 1,
    "website_id": 1,
    "addresses": [],
    "disable_auto_group_change": 0,
    "extension_attributes": {
        "is_subscribed": false
    }
}

但是,当我尝试与同一个用户登录以获得令牌时,它会给我一条类似错误的消息。在magento2中是否有其他方法可以使用rest获取用户令牌/登录?

代码语言:javascript
复制
    API: Login

URL: http://demo-acm-2.bird.eu/rest/all/V1/integration/customer/token
method : POST
Request Body

{
    "username" : "pradeep123@gmail.com",
    "password" : "Qwe@123123"
}

Response 

{
    "message": "You did not sign in correctly or your account is temporarily disabled."
}
EN

回答 1

Stack Overflow用户

发布于 2020-08-29 12:17:42

客户注册API

API名称:客户注册API

描述:创建客户帐户。执行必要的业务操作,如发送电子邮件。

baseurl:{rest URL}/rest/V1/customers

方法: POST

Body:

代码语言:javascript
复制
{
        "customer": {
            "email": "testtest123@gmail.com",
            "firstname": "Kavin",
            "lastname": "Peter",
            "addresses": [{
                "defaultShipping": true,
                "defaultBilling": true,
                "firstname": "Kavin",
                "lastname": "Peter",
                "region": {
                    "regionCode": "NY",
                    "region": "New York",
                    "regionId":43
                },
                "postcode": "10755",
                "street": ["123 Oak Ave"],
                "city": "Purchase",
                "telephone": "1234567890",
                "countryId": "US"
            }],
            "extension_attributes": {
                "is_subscribed": true
            },
            "custom_attributes": [
                {
                    "attribute_code": "customer_mobile",
                    "value": "1234567890"
                 }
            ]
        },
        "password": "test123"
    }

响应:

代码语言:javascript
复制
{
    "id": 55,
    "group_id": 1,
    "default_billing": "32",
    "default_shipping": "32",
    "created_at": "2020-08-29 12:10:14",
    "updated_at": "2020-08-29 12:10:31",
    "created_in": "Default Store View",
    "email": "testtest123@gmail.com",
    "firstname": "Kavin",
    "lastname": "Peter",
    "store_id": 1,
    "website_id": 1,
    "addresses": [
        {
            "id": 32,
            "customer_id": 55,
            "region": {
                "region_code": "NY",
                "region": "New York",
                "region_id": 43
            },
            "region_id": 43,
            "country_id": "US",
            "street": [
                "123 Oak Ave"
            ],
            "telephone": "1234567890",
            "postcode": "10755",
            "city": "Purchase",
            "firstname": "Kavin",
            "lastname": "Peter",
            "default_shipping": true,
            "default_billing": true
        }
    ],
    "disable_auto_group_change": 0,
    "extension_attributes": {
        "is_subscribed": true
    },
    "custom_attributes": [
        {
            "attribute_code": "customer_mobile",
            "value": "1234567890"
        }
    ]
}

登录API

API名称:登录API

Description:为客户凭据创建访问令牌。

baseurl:{rest URL}/rest/V1/integration/customer/token

方法: POST

Body:

代码语言:javascript
复制
{
        "username": "kirti.nariya@magedelight.com",
        "password": "test@$123"
    }

响应:

代码语言:javascript
复制
"bdw1x6cb3ntbdj6d4pqfzr8xksjezkv2"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61289394

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档