I'm calling the https://plaid.com/docs/api/tokens/#linktokencreate endpoint using the plaid-python libraries. When I create a link token request.
LinkTokenCreateRequest:
{'client_name': 'MYCLIENTNAME', 'country_codes': ['US'], 'language': 'en', 'products': ['auth', 'transactions'], 'user': {'client_user_id': 'XXXXXXXXXX'}, 'webhook': '/webhooks/091e07ab'}
The plaid response is:
{
"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
}
The request works if I leave out the webhook parameter. Here's the code:
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']
I've also tried with the full hostname and uri and both produce the same error. What is wrong with the request?
UPDATE 1:
I ran the test again and here's the output. One thing I noticed this time with the webhook in the token_request is it looks to be formatted incorrectly. I'm calling LinkTokenCreateRequest like so:
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
)
)
And the output for the call is below. You can see the webhook is generated with an empty string and then the webhook I provided.
[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
}
The webhook parameter needs to include the entire webhook endpoint URI, including the https:// part, in the request.