英文:
Is there a way for foundry function-backed actions to return a value when called via the API?
问题
根据此处的API文档,我知道我可以通过HTTP调用Foundry来应用一个操作:https://www.palantir.com/docs/foundry/api/ontology-resources/actions/apply-action/。我也知道操作可以是函数支持的:https://chapter.palantirfoundry.com/docs/foundry/action-types/function-actions-getting-started/。
我的问题是,可以让用于定义操作的函数返回一些值(比如创建对象的ID),并将该值返回到API调用的响应体中吗?
我注意到ApplyActionResponse的返回类型只是一个空的JSON对象。这是否意味着无法从端点返回任何内容?
英文:
Based on the API documentation here, I know I can make an HTTP call to Foundry to apply an action: https://www.palantir.com/docs/foundry/api/ontology-resources/actions/apply-action/. I also know that action can be function-backed: https://chapter.palantirfoundry.com/docs/foundry/action-types/function-actions-getting-started/.
My question is, can you have the function used to define an action return some value (say the ID to a created object), and have that value be returned in the API call response body?
I noticed that the return type of the ApplyActionResponse is just an empty JSON object. Does this mean that nothing can be returned from the endpoint?
答案1
得分: 0
简短回答: 今天不行
可能的解决方法:
- 在客户端生成对象的唯一标识符,并在提交请求完成后发出获取该对象的请求。这是我过去常做的事情。通常我使用UUID来实现这一点,因为其他类型的主键可能不唯一(例如递增整数)。无论如何,在您的主键不唯一的情况下最好包含重试逻辑。
- 如果您从Foundry可以与之通信的服务器上调用API,您可以在Action中添加一个Webhook,用于将您需要发送到服务器的任何数据发送给您的服务器。我尚未测试过这一点,但似乎应该是可能的。
英文:
Short Answer: Not today
Possible workarounds:
- Generate the unique id for the object on the client and make a get request for that object after the post request finishes. This is what I've done in the past. I usually use UUIDs for this since other sorts of primary keys may not be unique (e.g. an incrementing integer). In any case, best to include retry logic in the event your PK is not unique.
- If you're calling the API from a server that Foundry can communicate with, you could potentially add a webhook to your Action that would send whatever data you need to send to your server. I haven't tested this, but it seems like it should be possible.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论