【问题标题】:Magento 2 rest api throws 401 Unauthorized errorMagento 2 rest api 抛出 401 Unauthorized 错误
【发布时间】:2016-04-11 22:01:11
【问题描述】:

我在 Magento 2 中创建了一个用户角色和一个新用户 image capture

我在 Chrome 中使用了 Postman 应用程序:

在 GET 框中:http://example.com/php.index/rest/V1/products/ 在类型中使用带有用户名和密码的基本身份验证

但是我得到这个状态'401 Unauthorized'并且这个请求:

    {
  "message": "Consumer is not authorized to access %resources",
  "parameters": {
    "resources": "Magento_Catalog::products"
  }
}

我可以使用用户名和密码登录 Magento 后端

有什么办法吗?

【问题讨论】:

    标签: api rest magento2


    【解决方案1】:

    您需要在标头中使用访问密钥传递基本授权:

    第 1 步:

    调用 API:/V1/integration/admin/token 带参数:

    username=your_admin_username
    password=your_admin_password
    

    这将为您提供一个访问密钥,例如 at0o6w5rhno6sltcuhf3****k0603l

    第二步:

    调用 API:/V1/products/ 带参数

    searchCriteria=*
    Put **Header**
    Authorization : Bearer at0o6w5rhno6sltcuhf3****k0603l 
    Content-Type : application/json
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 2016-11-28
      • 2017-05-14
      • 1970-01-01
      • 2017-06-25
      • 2020-04-15
      • 2020-01-10
      相关资源
      最近更新 更多