Skip to content

URL sources and credentials

Save a feed's address once, then fetch it whenever you import or on a schedule. A credential sends an API key in a request header, or holds a secret such as a private key, stored encrypted and never shown again.

A URL source is a saved address the site fetches data from: a CSV export, a JSON API, an XML feed. You can import from it in the wizard, and a schedule needs one. How the data is read (CSV, JSON, XML and so on) comes from the template, not from the source.

From version 0.9.0, the same list can also hold other kinds of source, such as the FTP, SFTP and SQL Server connectors of Flux Importer Pro.

the Sources tab of Flux Importer in the EmDash admin, with URL sources and credentialsthe Sources tab of Flux Importer in the EmDash admin, with URL sources and credentials
The Sources tab: URL sources with their last fetch, and the credentials they send.
  1. Open Imports in the admin sidebar, then the Sources tab.
  2. Choose Add a source.
  3. Enter a Name (1 to 100 characters, unique on the site) and the Address.
  4. If the feed needs a key, pick a Credential. Add the credential first if you haven’t.
  5. Choose Save.

The address must start with http:// or https://, can’t contain a user name or password, and can be at most 2,048 characters. The list shows only its host and path, because a query string can hold a secret.

You can also save a source from the wizard: in the Source step, the From a URL tab asks for an address and a name, and fetching it saves it. The Saved source tab lists the sources you already have.

Fetch now on a source’s row downloads it straight away, so you can check that the address works. The site keeps the downloaded copy for the next import.

Each fetch after the first asks the server whether the feed changed (with the ETag and Last-Modified headers the server sent last time) and compares the content’s SHA-256 hash with the previous copy. The admin then says New content fetched. or No change since the last fetch.

The Last fetch column shows Never fetched, Fetched with the time and the size, or Failed with the time and the reason. Once an import or a dry run has read the fetched copy, the size comes with its record count, such as “10 records · 4 kB”. These are the reasons a fetch can fail:

Code What happened
URL_BLOCKED The address, a redirect, or an address its host name resolves to is not allowed. See Allowed hosts.
FETCH_FAILED The server could not be reached: DNS failed, the connection failed, no response came within 15 seconds, or the download took over 120 seconds.
HTTP_ERROR The server answered with a status outside 200 to 299.
TOO_MANY_REDIRECTS The server redirected more than 5 times.
TOO_LARGE The response is larger than the size limit. See Size limits.
LENGTH_REQUIRED On Cloudflare Workers only: the response gave no usable Content-Length and was larger than 32 MiB.
CREDENTIAL_MISSING The source’s credential has been deleted, or is now a secret, which a URL source can’t send.
CREDENTIALS_UNAVAILABLE The site can’t decrypt its credentials. See The encryption key.

The full list of codes is in Error codes.

When a fetch fails with HTTP_ERROR, the row shows the status the server answered, such as “HTTP 503 from the server”. From version 0.9.0, a server that explains the error in a JSON body of the form { "error": { "code": "…", "message": "…" } }, as Flux Relay does, gets its own words shown too:

  • the row shows the status and the server’s code, such as “HTTP 401 · UNAUTHORIZED”;
  • Fetch now says “Couldn’t fetch” with the reason, and the server’s code and message in brackets;
  • the source’s lastError keeps them as remote (code and message), next to the HTTP status.

Only a body sent as application/json, at most 8 KiB, with a code of capital letters, digits and underscores, is read. The message is cut to 500 characters, and control and text-direction characters are removed. Any other body is ignored, and the error shows its status only.

Open the ⋯ menu on a source’s row and choose Edit or Delete.

Changing the address or the credential clears the source’s fetch history, so the next fetch downloads everything again. A schedule keeps the address and credential it was set up with, so a schedule that reads the source would pause at its next run. The Edit dialog names those schedules and offers Also update these schedules, ticked by default. Updating them also clears their failed launches, and they then run as you.

You can’t delete a source a schedule reads. Delete the schedule, or switch it to another source, first. Deleting a source keeps the imports already made from it.

A credential is a named value stored on the site. One credential can serve several sources.

Credentials are write-only. Once saved, a value is never shown again, in the admin or through the API. The list shows the name, the header (or Secret) and how many sources use it.

A credential is one of two kinds:

  • Sent as a header: a header and value that the site sends with a URL source’s request, such as an Authorization header with a bearer token. This is the kind URL sources use.
  • Secret, from version 0.9.0: a value with no header, which can span several lines, such as an SFTP private key. Only other kinds of source use secrets. A URL source can’t send one, so it can’t pick a secret, and a URL source whose credential is replaced by a secret of the same name fails its fetch with CREDENTIAL_MISSING.

Credentials saved before version 0.9.0 are headers.

  1. On the Sources tab, choose Add a credential.
  2. Choose its Kind: Sent as a header or Secret.
  3. Enter a Name: lowercase letters, digits and hyphens, up to 64 characters.
  4. For a header, enter the Header the value is sent in, such as Authorization or X-Api-Key.
  5. Enter the Value. A header’s value, such as Bearer sk_live_…, is 1 to 4,096 printable ASCII characters, with no line breaks. A secret is 1 to 16,384 characters and may hold tabs and line breaks, but no other control characters.
  6. Choose Save credential.

Some headers can’t carry a credential, because the request needs them for itself: Host, Cookie, Content-Length, Transfer-Encoding, Connection, Keep-Alive, Proxy-Connection, Proxy-Authenticate, Proxy-Authorization, TE, Trailer, Upgrade, If-None-Match and If-Modified-Since.

The credential is sent only to the source’s own origin. If the server redirects to another host, the header is removed before the redirect is followed. Media downloads never send a credential.

Replace sets a new value (and, for a header, a new header) under the same name. It keeps the credential’s kind. The sources that use it pick up the new value on their next fetch, and schedules that read them keep running.

Delete removes the credential for good. The dialog names the sources that use it. Their fetches fail with CREDENTIAL_MISSING until you add a credential with the same name again, and schedules that read them pause at their next run.

Credentials are stored in EmDash’s encrypted plugin settings, so the site needs the EMDASH_ENCRYPTION_KEY environment variable set. Without it, or with a malformed key, saving or using a credential fails with CREDENTIALS_UNAVAILABLE. Generate a key with EmDash’s CLI:

Terminal window
npx emdash secrets generate

On Cloudflare, store it as a Worker secret with wrangler secret put EMDASH_ENCRYPTION_KEY. Keep a copy somewhere safe: a database backup doesn’t include the key, and without it the stored credentials can’t be read. See EmDash’s guide to secrets.

From version 0.9.0, a package that wraps the importer can add kinds of source besides URLs. Flux Importer Pro adds FTP, FTPS, SFTP and SQL Server. Without such a package, the Sources tab holds URL sources only, and nothing here changes.

With one installed:

  • The list shows each source’s kind and host, such as “SFTP · sftp.example.com”, and the credentials its settings name.
  • Add a source offers a Kind: URL, or each kind the package adds. The dialog then asks for that kind’s settings instead of an address.
  • A setting that holds a password or a key is saved as a secret credential, named after the source and the setting, such as nightly-stock-password. When you edit the source, leave the field empty to keep the stored secret, or choose Remove to drop it.
  • An SFTP source remembers the server’s host key after its first successful fetch, and shows it. Forget clears it, so the next fetch accepts the key the server offers then. Changing the host or the port forgets it too.
  • Edit is offered for a kind whose installed package gives it a form. If the site can’t read the installed kinds, the tab says “Source kinds could not be loaded, so connector sources can’t be edited.”, with Try again.
  • In the wizard, the Saved source tab lists such sources as “Name (Kind)”.

Changing a source’s settings clears its fetch history, as changing a URL does, and the Edit dialog offers to update the schedules that read it.

Sources are fetched from your server, so the importer refuses addresses on your own network. It checks the address, every redirect (at most 5), and every IP address the host name resolves to, before it connects. A refused address fails with URL_BLOCKED. These are refused:

  • the host names localhost, metadata, metadata.google, metadata.google.internal and instance-data, and any name ending in .localhost, .local, .internal or .home.arpa
  • private, loopback, link-local, shared and reserved IPv4 ranges, such as 10.0.0.0/8, 127.0.0.0/8, 169.254.0.0/16, 172.16.0.0/12 and 192.168.0.0/16
  • every IPv6 address outside global unicast, and IPv6 forms that carry one of the IPv4 ranges above

On Cloudflare Workers, host names are resolved with DNS over HTTPS (cloudflare-dns.com).

Fetch from your own network in development

Section titled “Fetch from your own network in development”

To import from a feed on your machine or your local network while you develop, pass allowPrivateNetwork to fluxImporterRoutes():

astro.config.mjs
integrations: [
// …
fluxImporterRoutes({
allowPrivateNetwork: true,
}),
],

It only works in development (astro dev). Production builds ignore it, so you can’t switch the check off on a live site. It applies to URL sources and media downloads alike.

A fetch can be at most maxSourceBytes, the option of fluxImporterRoutes() that also limits uploads. The default is 50 MiB (52,428,800 bytes). A source read as XLSX is limited to 10 MiB, or to maxSourceBytes when that is lower. See Configuration and settings.

astro.config.mjs
fluxImporterRoutes({ maxSourceBytes: 100 * 1024 * 1024 }),

On Cloudflare Workers, a response without a usable Content-Length header (a compressed or chunked one, for example) is held in memory to measure it, up to 32 MiB. A larger one fails with LENGTH_REQUIRED.