【问题标题】:Plaid webhook must be a non-empty string URL格子 webhook 必须是非空字符串 URL
【发布时间】:2021-12-16 12:35:06
【问题描述】:

我正在使用 plaid-python 库调用 https://plaid.com/docs/api/tokens/#linktokencreate 端点。当我创建链接令牌请求时。

LinkTokenCreateRequest:

{'client_name': 'MYCLIENTNAME', 'country_codes': ['US'], 'language': 'en', 'products': ['auth', 'transactions'], 'user': {'client_user_id': 'XXXXXXXXXX'}, 'webhook': '/webhooks/091e07ab'}

格子的回应是:

{
"display_message": null,
"documentation_url": "https://plaid.com/docs/#create-link-token",
"error_code": "INVALID_FIELD",
"error_message": "webhook must be a non-empty string URL",
"error_type": "INVALID_REQUEST",
"request_id": "E************p",
"suggested_action": null
}

如果我省略了 webhook 参数,请求就会起作用。代码如下:

webhook_url = f"/webhooks/{user_hook_id}"
logger.info(f"webhook_url = {webhook_url}")
api_client = create_plaid_client()
client = plaid_api.PlaidApi(api_client)
token_request = LinkTokenCreateRequest( 
    products=[Products('auth'), Products('transactions')],
    webhook=webhook_url,
    client_name=client_name,
            country_codes=[CountryCode('US')],
            language='en',
            user=LinkTokenCreateRequestUser(
                client_user_id=user_hook_id
            )
        )
        logger.info(f"token_request = {token_request}")
        # create link token
        token_response = client.link_token_create(token_request)
        token = token_response['link_token']

我也尝试过使用完整的主机名和 uri,但都产生了相同的错误。请求有什么问题?

更新 1:

我再次运行测试,这是输出。这次我注意到 token_request 中的 webhook 的一件事是它的格式似乎不正确。我这样调用 LinkTokenCreateRequest:

token_request = LinkTokenCreateRequest( 
    products=[Products('auth'), Products('transactions')],
    webhook=webhook_url,
    client_name=client_name,
            country_codes=[CountryCode('US')],
            language='en',
            user=LinkTokenCreateRequestUser(
                client_user_id=user_hook_id
            )
        )

调用的输出如下。你可以看到 webhook 是用一个空字符串生成的,然后是我提供的 webhook。

[INFO]  2021-11-03T22:52:36.263Z    ba0ad99b-76bd-42bf-b096-ca3e75b764dc    webhook_url =  https://b4234etcA3.execute-api.us-east-1.amazonaws.com/dev/webhooks/64a0f8d03754
[INFO]  2021-11-03T22:52:36.429Z    ba0ad99b-76bd-42bf-b096-ca3e75b764dc    token_request = {'client_name': 'Test',
 'country_codes': ['US'],
 'language': 'en',
 'products': ['auth', 'transactions'],
 'user': {'client_user_id': '64a0f8d03754'},
 'webhook': ' '
            'https://b4234etcA3.execute-api.us-east-1.amazonaws.com/dev/webhooks/64a0f8d03754'}

2021-11-03T15:52:36.816-07:00            [ERROR] ApiException: (400)
            Reason: Bad Request
            HTTP response headers: HTTPHeaderDict({'Server': 'nginx', 'Date': 'Wed, 03 Nov 2021 22:52:36 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '289', 'Connection': 'keep-alive', 'plaid-version': '2020-09-14'})
            HTTP response body: {
                "display_message": null,
                "documentation_url": "https://plaid.com/docs/#create-link-token",
                "error_code": "INVALID_FIELD",
                "error_message": "webhook must be a non-empty string URL",
                "error_type": "INVALID_REQUEST",
                "request_id": "FrPnbQEDoQgI4f6",
                "suggested_action": null
            }

【问题讨论】:

    标签: python python-3.x plaid


    【解决方案1】:

    webhook 参数需要在请求中包含整个 webhook 端点 URI,包括 https:// 部分。

    【讨论】:

    • 我也试过了,结果一样。我在问题的底部提到了这一点
    • 您能否更新您的问题以显示您尝试过的请求的确切请求和响应?
    • 嗨,Alex,我的问题中的 LinkTokenCreateRequest 是打印出来的 logger.info(f"token_request = {token_request}") 行,格子响应来自格子的记录响应。我正在尝试针对沙盒环境的请求。再次感谢您提供的任何帮助。
    • 抱歉,澄清一下——我正在寻找正确设置 webhook 参数的调用的确切请求和响应,以便我们可以仔细检查 webhook 参数您传递的没有任何问题(因为错误代码表明 webhook 参数有问题)。
    • 请看更新1
    猜你喜欢
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 2022-01-16
    • 2022-07-15
    • 2021-12-04
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多