Is there a way for foundry function-backed actions to return a value when called via the API?

Based on the API documentation here, I know I can make an HTTP call to Foundry to apply an action: API Reference | 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?

Question originally asked by stevenc on Stack Overflow: Is there a way for foundry function-backed actions to return a value when called via the API? - Stack Overflow

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.

There might be another workaround: on the object type, save the user id (uuid in the user’s Foundry rid). Then, after object creation use a named Query API endpoint to get the most recent object created by that user. This has limited applicability (e.g. if users can create multiple objects in one request, etc.), but could be applicable to certain situations. Link to docs on Queries: palantir.com/docs/foundry/functions/query-functions/…

Ontologize

Jul 19, 2023 at 22:22

Answer originally provided by Ontologize on Stack Overflow: Is there a way for foundry function-backed actions to return a value when called via the API? - Stack Overflow