Accessing a typescript v2 function within a python transform

I’ve created a function to convert html to markdown within a typescript v2 function, and I want to utilise this within a python transform to convert some html to MD before storing it in a dataset. The documentation seems to suggest this should be possible by accessing the function api directly using a request to /api/ontology/functions/, but I keep getting a 404. Not sure if I’m doing something wrong or if it’s an egress policy that needs changing.

Thanks in advance!

Hi @AFitz,

To call a function through the API you must first give it an API name. Documentation on how to do that can be found here.

Then, to actually make the API request you can follow this documentation. Note that the path is /api/v2/ontologies/{ontology}/queries/{queryApiName}/execute.

thanks! I’d given the api a name already, and I’m guessing the {ontology} is the api name found in ontology manager-> configuration->API name?

atm it now gives a 401, even though I’ve passed through my bearer token, so I guess it’s now a permissions issue?

Does it work when you call the API with curl with the same token?

hmmm, it gives bad hostname when I use curl, which is odd because preview in code repository gives a 401, not a 404

edit: ah wait, invalid argument

yeah, when I fixed the invalid parameter, it gave url rejected, bad hostname on the curl

Can you share the curl command (feel free to replace the url with a placeholder)?

I just got it to work, realised I was using “result” in my code instead of “value”, among some other issues :d’oh:

thank you all very much for your help!

for other people’s future reference, this is the code which I used which worked:

ONTOLOGY_FUNCTION_URL = "https://<YOUR GROUP NAME>/api/v2/ontologies/<YOUR ONTOLOGY API NAME>/queries/<YOUR FUNCTION API NAME>/execute"
def extract_markdown(html):
    responseMD = requests.post(
        ONTOLOGY_FUNCTION_URL,
        json={"parameters": {"htmlString": html}},
        headers={"Authorization": f"Bearer {AUTH_TOKEN}"},
    )
    responseMD.raise_for_status()
    return responseMD.json()["value"]
1 Like