MCPcopy Create free account
hub / github.com/api3dao/airnode / callApi

Function callApi

packages/airnode-node/src/api/index.ts:297–326  ·  view source on GitHub ↗
(payload: ApiCallPayload)

Source from the content-addressed store, hash-verified

295}
296
297export async function callApi(payload: ApiCallPayload): Promise<LogsData<ApiCallResponse>> {
298 const verificationResult = verifyCallApi(payload);
299 if (verificationResult) return verificationResult;
300
301 const {
302 aggregatedApiCall: { parameters },
303 } = payload;
304 const ois = payload.config.ois.find((o) => o.title === payload.aggregatedApiCall.oisTitle)!;
305 const endpoint = ois.endpoints.find((e) => e.name === payload.aggregatedApiCall.endpointName)!;
306 const { endpointParameters: processedEndpointParameters } = await preProcessEndpointParameters(endpoint, parameters, {
307 totalTimeoutMs: PROCESSING_TIMEOUT,
308 });
309
310 // Skip API call if operation is undefined and fixedOperationParameters is empty array. We can be sure that there is
311 // at least one processing specification defined (either v1 or v2) because it is verified by the OIS schema.
312 if (!endpoint.operation && isEmpty(endpoint.fixedOperationParameters)) {
313 // The pre-processing output can be used as output directly or it can be used to manipulate parameters to use in
314 // post-processing.
315 return processSuccessfulApiCall(payload, { data: processedEndpointParameters });
316 }
317
318 const [logs, response] = await performApiCall({
319 ...payload,
320 aggregatedApiCall: { ...payload.aggregatedApiCall, parameters: processedEndpointParameters },
321 } as ApiCallPayload);
322 if (isPerformApiCallFailure(response)) {
323 return [logs, response];
324 }
325 return processSuccessfulApiCall(payload, response);
326}

Callers

nothing calls this directly

Calls 4

verifyCallApiFunction · 0.85
processSuccessfulApiCallFunction · 0.85
performApiCallFunction · 0.85
isPerformApiCallFailureFunction · 0.85

Tested by

no test coverage detected