6

我构建了一个小程序,可以帮助识别 Demandware 中状态不正确的订单,例如:(状态:新的、打开的、已完成的和运输状态:未发货、已发货)。

我基本上只是使用 OCAPI 的 order_search 并将结果与​​我们的 ERP 进行比较。

但是现在我想自动化一些状态修复,这需要我使用 /orders/{order_no} GET 和 PATCH 调用,但是当我这样做时,我收到以下消息:

{ type: 'AccessWithoutUserForbiddenException',
 message: 'An authenticated user is required in order to access resource.' }

根据 order_search 的文档 OAUTH 使用:“通过 OAuth 令牌进行身份验证。”,但是 orders/{order_no} 使用:“通过 OAuth 令牌进行身份验证。需要有效的用户。”

那么成为有效用户的正确策略是什么?

4

2 回答 2

4

获取 oAuth 令牌的有效用户是 Business Manager 用户。因此,请登录 Business Manager 并为您的用例创建一个新用户并授予必要的权限。

之后,您可以执行特定资源。

基督教

于 2016-11-28T09:16:57.007 回答
1

如果您使用 account.demandware.com 作为主机,那么它将抛出以下错误

{ error: 'unauthorized_client', error_description: 'Client id \'xxxxxxxxxxxxxxxxxxx\' 的凭据无效,无法使用授权类型 \'urn:demandware:params:oauth:grant-type:client-id:dwsid:dwsecuretoken\'。' }

相反,您可以将主机更改为沙盒主机。再试一次。它应该工作。我也面临同样的问题。

const key = new Buffer('business_manager_email_id' + ":" + 'business_manager_pwd' + ":" + 'client_pwd').toString("base64");
const options = {
    url: 'https://<sandbox_host>/dw/oauth2/access_token?client_id=your_client_id',
    method: "POST",
    headers: {
      'Authorization': "Basic " + key,
      "Content-Type": "application/x-www-form-urlencoded",
    },
    body: "grant_type=urn:demandware:params:oauth:grant-type:client-id:dwsid:dwsecuretoken"
  };
于 2020-01-14T14:21:43.120 回答