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.