Budibase/budibase · error · HTTPError

Import data or url is required

Error message

Import data or url is required

What it means

createImporter requires either a `url` or non-empty `data` input describing the import payload. After trimming, if no data string is present it throws HTTPError 400 'Import data or url is required'. It prevents creating an importer from an empty/undefined payload.

Source

Thrown at packages/server/src/api/controllers/query/import/index.ts:162

  )
  return result
}

export async function createImporter(
  input: { data?: string } | { url?: string }
): Promise<RestImporter> {
  let cacheKeyBase: string | undefined
  let data: string | undefined
  if ("url" in input && input.url) {
    cacheKeyBase = buildCacheKey({ url: input.url })
    data = await urlToSpecs(input.url, cacheKeyBase)
  } else if ("data" in input) {
    data = input.data
  }

  data = data?.trim()
  if (!data) {
    throw new HTTPError("Import data or url is required", 400)
  }

  let cachedType: string | undefined
  const importerTypeCacheKey = cacheKeyBase && `${cacheKeyBase}:type`
  if (importerTypeCacheKey) {
    const client = await redis.clients.getOpenapiImportSpecsClient()
    cachedType = await client.get(importerTypeCacheKey)
  }
  const importer = await RestImporter.init(data, cachedType)

  if (!cachedType && importerTypeCacheKey) {
    const client = await redis.clients.getOpenapiImportSpecsClient()
    await client.store(
      importerTypeCacheKey,
      importer.getSource().getImportSource(),
      cache.TTL.ONE_DAY * OPENAPI_SPEC_CACHE_TTL_DAYS
    )
  }

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Ensure the request body includes either `data` (the spec/curl string) or `url`
  2. Check that the file/field you read the spec from is actually populated before sending
  3. Trim/validate client-side and show a validation message when the field is empty

Example fix

// before
await createImporter({ data: fileInput.value ?? "" }) // throws when empty
// after
if (!fileInput.value?.trim()) throw new Error("Please provide a spec or URL")
await createImporter({ data: fileInput.value })
Defensive patterns

Strategy: validation

Validate before calling

function validateImporterInput(input: { data?: string; url?: string }) {
  if (!input.data?.trim() && !input.url?.trim()) {
    throw new Error("Provide either a spec payload (data) or a URL")
  }
  return input as { data: string } | { url: string }
}

Type guard

const hasImportPayload = (i: unknown): i is { data: string } | { url: string } =>
  typeof i === "object" && i !== null &&
  (("data" in i && typeof (i as any).data === "string" && !!(i as any).data.trim()) ||
   ("url" in i && typeof (i as any).url === "string" && !!(i as any).url.trim()))

Try / catch

null

Prevention

When it happens

Trigger: Calling createImporter/getImportInfo with `{}` (neither key), `{ data: "" }`, `{ data: " " }` (whitespace only), or `{ data: undefined }`.

Common situations: A frontend form submits before the user pastes a spec; a file upload reads as an empty string because the wrong form field was read; an automation passes a variable that resolved to empty.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/ec35cab42f2df958. Report an issue: GitHub.