File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,7 +48,14 @@ export async function fetchAllResources(resourceType: ResourceType): Promise<Vap
4848 throw new Error ( `API GET ${ endpoint } failed (${ response . status } ): ${ errorText } ` ) ;
4949 }
5050
51- return response . json ( ) as Promise < VapiResource [ ] > ;
51+ const data = await response . json ( ) ;
52+
53+ // Handle paginated response format (e.g., structured-output returns { results: [], metadata: {} })
54+ if ( data && typeof data === "object" && "results" in data && Array . isArray ( data . results ) ) {
55+ return data . results as VapiResource [ ] ;
56+ }
57+
58+ return data as VapiResource [ ] ;
5259}
5360
5461// ─────────────────────────────────────────────────────────────────────────────
@@ -210,7 +217,13 @@ export async function pullResourceType(
210217) : Promise < PullStats > {
211218 console . log ( `\n📥 Pulling ${ resourceType } ...` ) ;
212219
213- const resources = await fetchAllResources ( resourceType ) ;
220+ const resources = await fetchAllResources ( resourceType ) ?? [ ] ;
221+
222+ if ( ! Array . isArray ( resources ) ) {
223+ console . log ( ` ⚠️ No ${ resourceType } found (API returned non-array)` ) ;
224+ return { created : 0 , updated : 0 } ;
225+ }
226+
214227 console . log ( ` Found ${ resources . length } ${ resourceType } in Vapi` ) ;
215228
216229 const reverseMap = buildReverseMap ( state , resourceType ) ;
You can’t perform that action at this time.
0 commit comments