Table Of Contents
The Journal for Cultural and Religious Theory has been publishing since 1999. As of this week, all 829 articles in its numbered archive have DOIs, deposited across 67 public collections in Knowledge Commons Works. This is the post I wanted to read before I started.
It is not a post about metadata theory. It is about the specific Python script you run, the specific environment variables it reads, the specific prompts it asks you, and the specific ways I made it fail before it worked. If you edit a small journal and someone has told you that you should get DOIs, this is roughly what that costs.
A warning about scale, up front: the importer is the easy part. It took an afternoon to learn. Getting 829 records into a shape the importer would accept took months. I'll be honest about that ratio at the end, because a how-to that only covers the fun part is a lie by omission.
The parts, and what talks to what #
I spent longer than I want to admit being confused about the names, so:
Knowledge Commons is the nonprofit scholarly network. MESH is, as Ian Scott put it to me, "basically the MSU institutional socket" — the arrangement through which Michigan State supports Knowledge Commons. From MSU's side, Knowledge Commons is a project of MESH; from its own side, Knowledge Commons is an independent entity with its own governance that draws support from MSU among others. Which framing you get depends on which side you're standing on.
Inside Knowledge Commons there are three distinct web applications that talk to each other: Works (the repository), Sites (WordPress), and Profiles. The cohesion of the design fooled me completely — I assumed Works was another WordPress thing. It is not. Works runs InvenioRDM, the same repository platform behind Zenodo. This matters practically, because when the KC Works documentation runs out, the InvenioRDM REST API documentation is where you go next, and it uses different vocabulary: what KC Works calls a collection, InvenioRDM calls a community. Every API path says communities.
Also: nerds, we need to name things better.
What has to exist before the importer helps you #
The importer takes two things per batch and sends them to Works:
- A metadata JSON file — an array of record objects, even when there's only one record. This is the part that took months.
- A ZIP of the PDFs those records refer to. The filenames inside the ZIP must exactly match the file entries named in the metadata.
Plus two things on the Works side:
- A collection you own, which must be public. (I'll come back to this.)
- An API token tied to your account.
The metadata shape is documented in the KC Works metadata reference. The parts I'd flag, because I got each of them wrong first:
resource_typefor a journal article istextDocument-journalArticle.- Creators are
{person_or_org: {type, name: "Family, Given", given_name, family_name}, role: {id: "author"}}. Thenamereally is "Family, Given" — inverted, comma-separated. - The journal's ISSN goes in
custom_fields["journal:journal"].issn. It does not go inmetadata.identifiers. An ISSN identifies a journal, not an article; putting it on the article is a category error that KC Works will happily accept and that will then be wrong in every record you deposit. - Controlled subjects want
{id, subject, scheme}, and theidhas to be the exact authority URI string the repository keys on. For FAST that ishttp://id.worldcat.org/fast/889115— note thehttp, nowww, noid.worldcat.org/fast/fst00889115variant. For Homosaurus it'shttps://homosaurus.org/v3/homoit0000560. Close is not close enough; a near-miss URI silently fails to match the authority. parent.access.owned_byis the depositor, not the author. For a journal archive that's you, the editor, on every single record, identified by your Knowledge Commons username with schemekc_username.
Getting the script #
The importer lives in the KC Works repository: scripts/user_resources/kcworks_api_importer.py. Documentation is under Using the KCWorks API importer script.
It needs Python 3.9 or later — Ian suspected 3.12+, and I ran it on 3.14 — and requests. In the journal's metadata repo:
python3 -m venv .venv
.venv/bin/pip install requests
Now, my first error, which I am recording because it will happen to somebody else this week. I "downloaded" the script from GitHub and ran it:
File "kcworks_api_importer.py", line 159
<title>knowledge-commons-works/scripts/user_resources/kcworks_api_importer.py at main · MESH-Research/knowledge-commons-works</title>
^
SyntaxError: invalid character '·' (U+00B7)
I stared at that middle dot for a genuinely embarrassing amount of time trying to work out where in my data a U+00B7 had come from. It had come from GitHub. I had saved the HTML page rather than the file. Use the raw view, or GitHub's download button, or curl -o. Python's syntax error, in its defence, was telling me exactly what was in the file; I just wasn't listening.
Three ways to feed it #
The script accepts input three ways, and understanding the precedence is most of what you need:
command-line argument → environment variable → interactive prompt.
| Argument | Environment variable |
|---|---|
--api-key |
KCWORKS_IMPORT_API_KEY |
--collection-id |
KCWORKS_IMPORT_COLLECTION_ID |
--metadata |
KCWORKS_IMPORT_METADATA_PATH |
--files |
KCWORKS_IMPORT_FILES_PATH |
--output |
KCWORKS_IMPORT_OUTPUT_PATH |
So the fully explicit form is:
python3 kcworks_api_importer.py \
--api-key "$TOKEN" \
--collection-id "jcrt-251" \
--metadata /abs/path/archives/25.1.metadata.json \
--files /abs/path/archives/25.1.zip \
--output /abs/path/_logs/25.1.log
--metadata is a path to the JSON file, not to a directory — I asked, and asking saved me a round trip. --files takes one or more paths. --output is where the JSON report of the import gets written, and you want it: it is the record of what actually happened, and it's what you'll parse afterward to get your DOIs back.
Or run it with no arguments at all, and it becomes an interactive dialogue:
$ python3 kcworks_api_importer.py
Enter your KCWorks API key: ········
Enter the KCWorks collection ID for the import: jcrt-251
Enter the path to the metadata JSON file: archives/25.1.metadata.json
Enter the path(s) to the files (space-separated): archives/25.1.zip
Enter the path to save the response JSON (optional, press Enter to skip):
Every prompt validates as you go — a metadata path that doesn't exist, or points at a directory instead of a file, exits with an error rather than failing later against the server. The output prompt is the only optional one; pressing Enter skips saving the report. Don't skip it.
The interactive mode is genuinely the right way to run your first import. You see what the script wants, in order, and you can't typo a flag name.
The .env, and a thing worth being precise about #
I asked Ian whether the script would read a .env file. He wasn't sure off the top of his head, and said he'd check. Having now read the script: it does not. It reads os.environ. A .env file is inert to it unless something puts those values into your environment first.
That distinction is easy to lose because the practical fix makes it look like .env support:
set -a
source .env
set +a
set -a marks everything subsequently assigned for export, so sourcing the file puts its variables into the environment the script inherits. set +a turns that back off. Three lines, and now your .env works — but through the shell, not through the script.
My whole .env is two lines:
KCWORKS_IMPORT_API_KEY=…
KCWORKS_IMPORT_OUTPUT_PATH=_logs/{issue}.log
The {issue} is my own convention, not the script's — my wrapper substitutes the issue number before passing the value along, so each issue writes its own log. Gitignore this file. I keep the API key out of --api-key on the command line specifically so it doesn't land in shell history.
The token, and the collection #
The token comes from works.hcommons.org/account/settings/applications/ — a page that is currently unlinked from the interface, because KC Works uses Knowledge Commons profiles rather than InvenioRDM's own account system, and the account area exists but isn't meant to be a destination. Ian's exact instruction was "please just don't touch anything else in there," which I pass along. Click New Token, name it, don't worry about scopes, create it, and copy it immediately — you don't get to see it again.
Two things about the target collection:
It must be public. A brand-new private collection is not a safe place to rehearse; make the collection public before importing into it.
Its slug is the --collection-id. Not the display name — the slug from the URL. Make them match if you can, and save yourself the confusion.
Doing it 67 times #
Here is where I hit the actual problem. Ian walked me through one import, it worked, and then I said the quiet part out loud: I was going to be doing this "40 some odd times." It turned out to be 67. My exact response on the call was "It's fine. I'm crying. It's okay."
You have three options.
One collection for everything. Amalgamate all the metadata into one array, all the PDFs into one ZIP, one upload. Simplest. Your readers then browse 829 records in one undifferentiated list.
One collection per issue. Better for readers, which is why I chose it, and worse for you, because now you're creating 67 collections. Sub-collections — where each issue nests under a parent JCRT collection with breadcrumbs and a browse tab — are coming in a later KC Works release, and existing collections can be adopted into a parent when they land. So creating them flat now is not wasted work.
Script it. Collections are creatable through the InvenioRDM communities API. Anything you can do in that interface you can do over HTTP.
I scripted it, which is the third option, and I want to be careful about how I recommend that. Ian's suggestion, when the subject came up, was that someone not comfortable writing the Python could ask an agent to write it — and then immediately added the caveat: "that is dangerous, though, if you don't know how to debug the script well."
That is exactly right, and it is a rule I already keep: I don't have AI write languages I don't speak. I can debug JavaScript and shell. So my wrapper is a bash script that shells out to the vendor's Python, which I read but did not modify beyond one change. When it breaks, I can fix it. If I'd generated 400 lines of Python I couldn't read, the first 500 error would have ended the project.
What the wrapper does #
./import.sh 25.1 — one issue at a time. Before it makes any network request, it:
- checks the metadata sidecar and ZIP both exist;
- renders and validates the collection's profile image (800×800, 72 DPI, under 1 MiB, which KC Works requires);
- prints the issue, the collection URL, the record count, and every article title with its file, so I can look at it before agreeing;
- runs a local preflight (below).
Then it asks, separately, before each irreversible thing: create the collection? upload the profile image? import this metadata and ZIP? It reuses an existing collection rather than duplicating one, tags the collection as type journal, checks that the token user is actually an owner and makes that ownership public, and stops if it isn't.
./import.sh --check 25.1 does everything up to the first network call and stops. That's the command I ran dozens of times.
Two hard-won details in there. A collection slug cannot be reused after deletion — delete a collection you made by mistake and that slug is gone. And import in small batches; I capped mine at four records. Ian's advice was not to run several imports simultaneously at first, and to watch each one's output before continuing, which is correct and which I'd extend: reconcile against the live collection before every batch, import only what's missing, re-query after, and stop if a batch made no progress. The one change I made to the vendored importer was to have it exit non-zero after a non-201 response, so a partial server failure can't be mistaken for success by a wrapper that only checks exit codes.
Preflight, because there is no dry run #
The importer has no --dry-run. Once you press Enter, records are being created on a live public repository. So the last honest checkpoint is local, and I built one: it extracts the issue's ZIP into a temp directory and validates the metadata against the contract before anything leaves the machine.
It checks that title, publication date, publisher, and description are strings and non-empty; that the publication date is EDTF (YYYY or YYYY-MM-DD); that a resource type is present; that creators exist and each has a name; that any ORCID matches \d{4}-\d{4}-\d{4}-\d{3}[\dX] and any ISNI is 16 characters; that creator identifier schemes are only orcid, isni, or kc_username; that subject ids are well-formed FAST or Homosaurus URIs with a recognized scheme; and that every file entry names a file that is actually inside the ZIP.
None of that is exotic. All of it caught something. The subject-URI check alone caught an entire category of records that would have deposited with authority headings that matched nothing.
The one idea worth stealing: import-recid #
If you take one thing from this post, take this.
Every page in the journal's source repository carries a stable six-character id in its front matter — a nanoid, generated once, never changed, guarded by a pre-commit hook and a CI check so a new article cannot be committed without one. The metadata generator exports that id as an identifier with the scheme import-recid.
That single stable key is what turned an 829-record migration from a stunt into a process:
- Reconciliation. Before each batch, query the live collection and collect the
import-recidvalues already there. Import only the ones missing. A batch that half-failed is not a disaster; it's a shorter next batch. - Resumability. I could stop at any point, and did, repeatedly, over days.
- Mapping DOIs home. When the import returns record ids, fetch each record, read its
import-recid, and you know exactly which source file it came from. Not "probably this one, the titles match" — exactly.
The DOI sync in my wrapper refuses to run unless the log is a complete success with the expected record count, and for each returned record it requires that exactly one Markdown file in the issue carries that recid. One match, or it stops and tells me why. It has stopped on me. It was right every time.
Without a stable id you are matching on titles, and titles in a twenty-seven-year archive are not unique, not stable, and not always correct.
Getting the DOIs back into the site #
After a successful import, for each record in the log: fetch the record, read pids.doi.identifier and the import-recid, find the one source file with that id, and write the DOI into its front matter — refusing to overwrite an existing, different DOI.
That last refusal matters more than it sounds. It is the check that catches the case where you've re-imported something that was already deposited, and it's the difference between a sync you can run confidently and one you have to supervise.
Two things I'd tell you that nobody told me #
Files on a published record are permanent. InvenioRDM locks the file bucket when a record is published. If you deposit the wrong PDF — and across 829 records assembled over 27 years, you may find that a wrong PDF was deposited long before you ever opened the importer — you cannot swap it. The API answers 403 Bucket is locked for modifications, and re-importing the same identifier returns 409 Conflict rather than updating. Your options are a new version, which mints a new version DOI while the parent DOI keeps resolving to the latest, or an administrator. Check your files before you publish, not after. I would say this more gently if I had not learned it the direct way.
Make the tool refuse rather than guess. Every place I let a script infer something — which file matches which record, which authority heading a subject probably means — I eventually had to go back and check its work. Every place a script stopped and made me look, I trusted the result. For a repository deposit, where the output is permanent identifiers attached to other people's scholarship, the cost of a stop is an afternoon and the cost of a wrong guess is a correction notice.
The honest ratio #
The import itself: one afternoon to learn, a few days of batches to execute.
Everything else: normalizing 27 years of front matter, restoring missing volume and issue and year values, repairing migration damage from earlier platforms, researching and verifying 3,601 controlled subject headings, generating 103 PDFs for articles that had only ever existed as web pages, giving all 795 archive PDFs a cover sheet with real embedded rights metadata, merging duplicate author records, and fixing an OAI-PMH endpoint that had been introducing the journal as a person. Months.
The repository is not the hard part. The repository is the thing that finally makes you fix your metadata, because it will not accept it otherwise. That turns out to be the actual value: not the DOIs, though the DOIs are what I promised our authors, but the fact that a machine with strict standards refused my archive until the archive was true.
Follow in our footsteps #
If you want the whole stack rather than just the deposit step, here is the shape of it. JCRT runs on a static site generator, two hosts, a repository, and no server that anyone has to keep alive. Total recurring cost is a domain name and, if you exceed the free tiers, a few dollars a month of object storage.
The pieces: Build Awesome (the package identity Eleventy now ships under) generates the site. Netlify builds and hosts it. Cloudflare R2 plus a Worker serves the PDFs and images from a separate subdomain. Pagefind does search in the browser. Pandoc and LuaLaTeX make the PDFs. KC Works holds the deposits and mints the DOIs. GitHub Actions glues it together.
1. Split the content from the files, on day one #
This is the decision I'd most want to hand you, because retrofitting it is miserable. Two repositories:
journal— Markdown, templates, config. Small. Rebuilds fast.journal-files— PDFs, images, citation exports, generated metadata. Large. Almost never needs a site rebuild.
Serve the second from its own subdomain (files.example.org). A journal archive is mostly bytes that never change; if those bytes live in the site repo, every build copies them and every deploy re-uploads them, and your build time grows with your back catalogue rather than with your content.
2. The content repo #
One Markdown file per article, one directory per issue. Front matter carries everything a citation needs: title, author, affiliation, volume, issue, pages, publication date, description, keywords, controlled subjects, PDF filename.
Two conventions I'd adopt immediately:
Give every page a permanent id. Six characters from nanoid, written into front matter once and never changed. Generate it with a script, stage it with a pre-commit hook, and gate the build on a check so a page cannot be published without one. This is what later becomes your import-recid, and everything downstream — deposits, DOI mapping, reconciliation — depends on it existing before you need it.
Make the build refuse. build:netlify on JCRT runs, in order: the nanoid check, sitemap generation, an external-records check, the Eleventy build, a sitemap validation, a quick OAI-PMH protocol validation, a CSS purge, a CSS optimizer, and the Pagefind index. Any failure fails the deploy. A static site's build is the only enforcement point you have; use it.
3. Netlify for the site #
netlify.toml, publish _site, and pin your Node version explicitly rather than inheriting the build image's default:
[build]
command = "npm run build:netlify"
publish = "_site"
[build.environment]
NODE_VERSION = "24"
ELEVENTY_ENV = "production"
SITE_URL = "https://example.org"
[build.processing]
skip_processing = true
skip_processing = true because your generator already handled the assets and you don't want two systems optimizing the same files. Add netlify-plugin-cache for .cache and .npm-cache — image processing and npm installs are most of a cold build.
4. Cloudflare R2 and a Worker for the files #
wrangler.toml is about as small as it gets:
name = "journal-files"
main = "src/worker.js"
compatibility_date = "2026-03-14"
[[routes]]
pattern = "files.example.org"
custom_domain = true
[[r2_buckets]]
binding = "FILES"
bucket_name = "journal-files"
The Worker reads from the bucket and returns the object. Mine is vanilla JavaScript, zero runtime dependencies, no framework, no build step — one route whose entire job is per-request policy. It has no write path at all: no POST, no DELETE, no KV. Everything it serves came from git.
Deploy with a content-addressed sync, not a diff. This is the single biggest thing I got wrong first. The original workflow looked at which files changed in a push and uploaded those, one wrangler r2 object put per file. Roughly two seconds of Node CLI startup each; a full sync took about thirty minutes. Worse, it was silently incomplete: a file committed while its folder was excluded, or during a cancelled run, simply never uploaded, and you found out when a reader hit a 404.
Now a single rclone run with --checksum compares the whole tracked tree against the bucket by hash and uploads only what differs. Push to live is under thirty seconds, and because every run compares everything, no file can fall through a window.
Two rules that follow from that:
- The workflow's path filter is an ignore-list, never an allow-list. A CDN must deploy any new folder without someone remembering to add it.
paths-ignorefor**/*.mdandLICENSE; everything else ships. - Deletion is explicit. The default sync copies. Removing remote objects that are no longer in git is a separate, manually dispatched run. Automatic deletion plus one bad glob equals an archive that isn't there any more.
5. Search #
Pagefind, built as the last step of the site build, indexing _site. It is a static index the browser queries; no server, no API key, nothing to keep running. If you run several sites, Pagefind's mergeIndex will search across them from the browser, provided each site sends CORS headers on /pagefind/*.
I tried the more ambitious thing first — browser-side semantic search over embeddings — and tore it out. That's its own post.
6. Make the archive machine-readable #
This is the part that turns a website into a journal, and it's mostly small template work:
- Zotero. Add
prefix="zotero: http://www.zotero.org/namespaces/export#"to your<html>and emitzotero:itemType. Article pages getjournalArticle; blog pages getblogPost. A warning learned the hard way:citation_journal_titleforces Zotero's translator to journal article, and a straycitation_titlein a blog branch makes it guess journal article. Keep those tags off non-article pages entirely. - Schema.org. A
metadata.jsonbeside each page, advertised with aLinkheader — the FAIR Signposting pattern. - OAI-PMH. Harvesters want it, DOAJ wants it, and it is a handful of XML templates over your existing collections. Validate it in the build; ours spent a while announcing the journal as a person.
- RIS and CSL JSON per article, generated into the files repo. That's what a "download citation" button serves.
7. PDFs, including the ones that don't exist yet #
Pandoc into LuaLaTeX with a journal-specific .tex template, a Lua filter for accessibility metadata, and a reference.docx if you also want Word output. One shell wrapper produces both formats from a Markdown file.
Then give every PDF in the archive a cover sheet — title, authors, stable URL, publisher, ISSN, rights — with the same values embedded as PDF metadata and a bookmark outline. Write a test that checks the visible cover text against the embedded metadata and run it in CI. Be honest with yourself about what this does and does not achieve: it makes your files citable and identifiable, and it does not make a 2003 page scan accessible.
8. Then, and only then, deposit #
Everything above is the prerequisite for the first half of this post. When your front matter is complete, your PDFs are canonical, and your ids are stable, generate the KC Works metadata sidecars and ZIPs, preflight them, and import issue by issue.
Do it in that order. Depositing is the step that tells you your metadata was wrong, and you would much rather learn that from a local validator than from 829 published records.
Thanks to Ian Scott at Knowledge Commons, who spent an hour walking me through the importer and then, when we hit something that wasn't my fault, went and read the server logs while I watched. That is what good infrastructure support looks like, and small journals do not usually get it.
The tooling described here is at github.com/the-Whitestone-Foundation/jcrt-meta. It is written for one journal and I make no claims about it generalizing, but the wrapper, the preflight, and the DOI sync are all readable in an afternoon, and you are welcome to steal any idea in them.
Tags : kcworks knowledge-commons invenio-rdm open-access digital-humanities dois python scholarly-publishing
Webmentions
No webmentions yet.