Hello everyone,
I’m encountering an issue with a Foundry Function using the Platform SDK and a TPA client, and I’m hoping someone can provide some clarity.
Situation
I want to use the Platform sdk with a tpa client inside a Functions.
I’m following the Use Platform APIs with the Foundry platform SDK documentation. However, instead of using the runtime client provided as a parameter, I am manually creating my own client.
To do this, I’m using createConfidentialOauthClient (from this documentation) with my tpa credentials to create a tokenProvider. I then use this tokenProvider with createClient to instantiate the client.
(As a side note, I have also added a data source with an HTTPS egress policy configured for the host address of the platform API.)
Symptoms
I wrote a Functions that uses this manually created client to call the Create Group api (via the Platform SDK) and create an ontology for the group.
I confirmed that this Functions runs successfully in live preview.
However, after I Tag and Release this Functions and create an Action from it, I get an error when I call the Action from workshop. The failure occurs at the API call step. (I don’t have the exact error message with me right now, but I should be able to attach it next week).
Questions
I’m trying to understand why this is failing. Is this failure related to the warning message in the Use an external source in a function documentation?
Third-party clients are not yet supported for serverless execution or live preview without overriding the fetch function or HTTP agent. To ensure your API calls function properly across all environments, you must use the relevant library methods to make requests with the correct configuration. Direct API calls to external sources or internal Foundry URLs are not guaranteed to work in all environments.
What’s confusing me is that the warning says it’s not supported in live preview, but it worked perfectly fine for me in live preview.
1. Would using deploy functions potentially solve this problem?
- As a temporary workaround, I referred to the webhook-client credentials grant documentation and registered the platform API as a webhook in Data Connection. I then import this webhook into my ts v1
Functions. This method does work correctly as an Action inworkshop.
Any insights on this would be greatly appreciated. I’m specifically hoping someone can clarify why the manual SDK client fails in the deployed Action (but not in preview), while the webhook method works perfectly.
Is my suspicion correct? Is this happening because, as the External Functions doc states, ‘External functions may not currently be used to make arbitrary API calls from TypeScript code without first defining the request as a webhook in Data Connection’?
Thanks!