Smooch Pre-Create 应用程序用户 API 需要范围应用程序和用户 ID,但也不允许用户 ID 与范围应用程序

Smooch Pre-Create App User API requires scope app and userId, but also doesnt allow userId with scope app

请求的验证与请求的要求之间似乎存在冲突。 API 调用要求范围设置为 'app'。它还需要一个 userId。但是,当两者结合时,您会收到以下消息,表明您不能将两者结合起来。

API https://docs.smooch.io/rest/#pre-create-app-user

请求

{ host: 'api.smooch.io',
  path: '/v1/appusers',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${token}`
}

例子body.

{
  scope: 'app',
  userId: 'some_userId',
  credentialRequired: true,
  email: 'test@email.com',
  properties: { picture: 'https://s.gravatar.com/avatar/.....' }
}

回应BODY

{"error":{"code":"bad_request","description":"Invalid JWT body. Cannot use userId param with app scope"}}

回应HEADERS

  { connection: 'close',
     server: 'nginx',
     date: 'Tue, 21 Feb 2017 14:47:50 GMT',
     'content-type': 'application/json; charset=utf-8',
     'content-length': '105',
     'x-powered-by': 'Express',
     vary: 'X-HTTP-Method-Override',
     etag: 'W/"69-huba/v8EazhrDAoySthrKw"',
     via: '1.1 vegur' },
  statusCode: 400,
  statusMessage: 'Bad Request' }

我认为您可能混淆了两个不同的概念 - JWT 负载与 HTTP 请求正文。

scope 在 JWT 凭证的有效负载中定义(代码示例中的 Bearer ${token})。有关 JWT 和范围的更多信息,请参见 here

userId 应在 HTTP 请求正文中指定。

我不确定你使用的是什么语言,但下面是 Node.js 中的示例:

var jwt = require('jsonwebtoken');
var token = jwt.sign({ scope: 'app' }, SECRET, { headers : { kid: KEY_ID } });

var request = require('request');
request.post({
    url: 'https://api.smooch.io/v1/appusers',
    headers: {
        'Authorization': `Bearer ${token}`
    },
    json: {
        userId: 'some_userId',
        credentialRequired: true,
        email: 'test@email.com',
        properties: { picture: 'https://s.gravatar.com/avatar/.....' }
    }
});