I have created a simple ontology with four objects - one primary object and three others that are foreign key-linked to the primary object. I would like to configure an existing API to consume data from Palantir Foundry. How can I use the SDK to serialize a primary object and each of its nested, foreign key-related objects to JSON?
There is a Build with AIP package called Getting Started with Ontology SDK (OSDK)
which is a very good example of how to achieve this. You can simply install it and follow the tutorial. There are more details about it in the announcements here: https://www.palantir.com/docs/foundry/announcements/#introducing-build-with-aip-for-ontology-sdk
You should find Build with AIP under YOUR_STACK_URL/workspace/now/platform
+1 on using the Ontology SDK (Look for Developer Console application on your Foundry instance).
Depending on your language of choice you will get something like this:
curl -X GET "https://<YOUR-STACK>/api/v2/ontologies/objects/{PrimaryObjectApiName}/{primaryKey}/links/{Name-of-the-link}" \
-H "Authorization: Bearer $TOKEN"
Or in TypeScript
import { GetLinkedObjectError, Result } from "@osdksampleapp/sdk";
import { Flight, Aircraft } from "@osdksampleapp/sdk/ontology/objects";
function getLinkedAircraft(source: Flight) {
return source.assignedAircraft.fetchOneWithErrors();
}
Thanks for your replies. I’ve stepped through the tutorial, but my question has more to do with retrieving data from multiple foreign key related objects in a single pass.
I am working on a solution for commercial lenders. In Foundry, I’ve created a primary object called Loan and have linked to it related objects called Borrower, Lender, and Collateral data.
Using the SDK, can I query a loan and get back all of these related objects?
For context, our application is written using Django/DRF and I’m trying to determine how we can leverage Palantir Foundry in our existing stack.
I don’t think you can retrieve an object and other linked objects at the same time. You would need one query for each distinct object type. When you create a Developer Console application, docs are generated with your object types, so you would get code snippets showing how you can get the linked objects from a Loan.
For instance, retrieving the borrower from the loan object could look like this in python:
from my_app_sdk.ontology.objects import Loan
def getLinkedBorrower(loan: Loan):
return loan.borrower.get()
If you have many 1-to-1, or many-to-one links, you could consider flattening your ontology for convenience: for instance by adding the Borrower and Lender properties directly to the Loan object type, so you would only need to query Loan.
If you want to all nested object (could be a large set) given a single top level object you can write a Function On Object function (TypeScript and soon Python) which get the root object key and get all the children and return them in a JSON or some other set.
If you mark this function as a Query and give it an API name you can add it to your SDK and use it in your APP or REST call.
See docs on Query.