Function call and webhook safety

I am trying to call a webhook and return its response with a return statement (instead of creating objects).

I have two problems I am looking for a workaround for:

  • The webhook has a “Writeback safety”, and says I cannot use it without the @OntologyEditFunction decorator but I see no mention of this in the docs or the webhook settings
  • The IDE highlights this error on the function itself: “Read-only Functions cannot call Webhooks with side effects. Called in refined_kpi_agg (index.ts)”

Here is the code:

    interface AggResults{
        key: string,
        category: string,
        doc_count: Integer
    }

    interface AggFilters{
        field: string,
        value: string
    }

export class MyFunctions {

    @Query({ apiName: "refinedKpiAgg" })
    public async refined_kpi_agg(filters: AggFilters[], aggregation:string): Promise<AggResults[]>{
        const result = await Sources.SearchLabelSource.webhooks.ReportAggRefined.call({
            filters: filters,
            aggregation: aggregation
        });
        if (isOk(result)) {
            let response: AggResults[] = result.value.output.response;
            return response
        }else{
            throw new UserFacingError(`Invalid Query.`);
        }
    }

The webhook is a basic POST with input and output as described in the function.

Hi,
I have run into similar issues recently, here are some points:

  • OntologyEditFunctions are not allowed to return anything, they should return a promise of void.
  • In Query() decorated functions, you are allowed only to make GET requests, POST/DELETE/PUT is not allowed. If you have control over the API you are calling and change it to be a GET (using URL parameters for inputs), it would work.
  • My workaround for this was to create an ephemeral object to store the results of the computation and use OntologyEditFunction to write results into an instance of that object type.