### Run Citoid Service (Bash) Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Commands to start the Citoid service using default or custom configurations, and to run its test suites. Ensure Node.js and npm are installed. ```bash # Start service with dev config npm ci node server.js # reads config.dev.yaml by default ``` ```bash # Start service with prod config SERVICE_CONFIG=config.prod.yaml node server.js ``` ```bash # Run tests (no live Zotero required) npm test ``` ```bash # Run full test suite including Zotero integration tests npm run test:zotero ``` -------------------------------- ### Service information Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Returns metadata about the running service instance including its name, description, version, and home URL. ```APIDOC ## GET `/_info` — Service information ### Description Retrieves metadata about the running Citoid service instance. ### Method GET ### Endpoint `/_info` ### Response #### Success Response (200 OK) - **Content-Type**: `application/json` - **Body**: JSON object containing service details. #### Response Example ```json { "name": "citoid", "description": "Converts search terms such as URL or DOI into citations.", "version": "3.0.0", "home": "https://www.mediawiki.org/wiki/Citoid" } ``` ``` -------------------------------- ### Access API Specification (Swagger UI) Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt The root endpoint provides access to the OpenAPI 3.0 specification. Append '?doc' to view the interactive Swagger UI documentation. ```bash curl "http://localhost:1970/?spec=true" ``` ```bash open "http://localhost:1970/?doc#!/Citations/get_api" ``` -------------------------------- ### API specification (Swagger UI) Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt The root endpoint serves the OpenAPI 3.0 spec or the Swagger UI documentation page. Append `?doc` to open the interactive docs. ```APIDOC ## GET `/` — API specification (Swagger UI) ### Description Serves the OpenAPI 3.0 specification or the interactive Swagger UI documentation. ### Method GET ### Endpoint `/` ### Query Parameters - **spec** (boolean) - Optional - If `true`, returns the raw OpenAPI spec as JSON. - **doc** (boolean) - Optional - If `true` (or if the parameter is present without a value), opens the interactive Swagger UI. ### Request Example ```bash # Retrieve the raw OpenAPI spec as JSON curl "http://localhost:1970/?spec=true" # Open interactive Swagger UI in a browser open "http://localhost:1970/?doc#!/Citations/get_api" ``` ``` -------------------------------- ### Configure Citoid Service (YAML) Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt This configuration file controls the runtime behavior of the Citoid service. Key options include Zotero integration, Wayback Machine fallback, PubMed enrichment, timeout settings, and polite-pool email for CrossRef/PubMed. ```yaml services: - name: citoid module: ./app.js conf: port: 1970 cors: "*" # External integrations zotero: true # Enable Zotero translation-server zoteroInterface: 127.0.0.1 zoteroPort: 1969 wayback: false # Enable Wayback Machine fallback for failed URLs pubmed: true # Wait for PubMed ID enrichment (PMID/PMCID/DOI) # CrossRef / PubMed polite-pool: supply email for better rate limits mailto: your@email.org # Race CrossRef vs URL resolution after this many ms (false = no timeout) timeout: 10000 # ms maxRedirects: 5 allowPrivateAddresses: false # User agent sent to external services user_agent: "citoid/3.0.0" ``` -------------------------------- ### Exporter.convertToWikibase Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Converts internal Zotero-format citation objects into Wikibase JSON format with identifiers. ```APIDOC ## `Exporter.convertToWikibase(citation, request)` ### Description Converts internal Zotero-format citation objects into Wikibase JSON format, including a nested object for identifiers. This is one of the supported output formats by the Exporter class. ### Method Exporter method ### Parameters - **citation** (object) - The citation object in Zotero format. - **request** (object) - The request object. ### Response Example (Output Format) ```json { "itemType": "journalArticle", "title": "...", "author": [["First", "Last"]], "identifiers": { "doi": "10.x/y", "pmid": "123", "pmcid": "PMC456", "isbn10": ["..."], "isbn13": ["..."], "url": "https://..." } } ``` ``` -------------------------------- ### Exporter.convertToBaseFields Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Converts internal Zotero-format citation objects into mediawiki-basefields JSON format. ```APIDOC ## `Exporter.convertToBaseFields(citation, request)` ### Description Converts internal Zotero-format citation objects into mediawiki-basefields JSON format. This is one of the supported output formats by the Exporter class. ### Method Exporter method ### Parameters - **citation** (object) - The citation object in Zotero format. - **request** (object) - The request object. ### Response Example (Output Format) ```json { "itemType": "journalArticle", "title": "...", "author": [["First", "Last"]], "publicationTitle": "...", "date": "...", "DOI": "..." } ``` ``` -------------------------------- ### Retrieve Service Information Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Fetch metadata about the running Citoid service instance, including its name, version, and home URL. This endpoint is useful for monitoring and understanding the service. ```bash curl "http://localhost:1970/_info" ``` ```json { "name": "citoid", "description": "Converts search terms such as URL or DOI into citations.", "version": "3.0.0", "home": "https://www.mediawiki.org/wiki/Citoid" } ``` -------------------------------- ### Exporter.convertToMediawiki Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Converts internal Zotero-format citation objects into mediawiki JSON format. ```APIDOC ## `Exporter.convertToMediawiki(citation, request)` ### Description Converts internal Zotero-format citation objects into mediawiki JSON format. This is one of the supported output formats by the Exporter class. ### Method Exporter method ### Parameters - **citation** (object) - The citation object in Zotero format. - **request** (object) - The request object. ### Response Example (Output Format) ```json { "itemType": "journalArticle", "title": "...", "author": [["First", "Last"]], "publicationTitle": "...", "date": "...", "DOI": "..." } ``` ``` -------------------------------- ### CitoidService.requestFromSearch Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Performs a free-text citation search against the CrossRef REST API, returning up to 2 results and mapping metadata to Zotero item types. ```APIDOC ## `CitoidService.requestFromSearch(citation, cr)` — Open-text search ### Description Performs a free-text citation search against the CrossRef REST API (up to 2 results), mapping returned metadata to Zotero item types via the CrossRef type translator. ### Method GET ### Endpoint `/mediawiki/{article_title}` ### Parameters #### Path Parameters - **article_title** (string) - Required - The URL-encoded article title text to search for. ### Request Example ```bash # Search by article title text (URL-encoded) curl "http://localhost:1970/mediawiki/The%20ENCODE%20Project%3A%20ENCyclopedia%20Of%20DNA%20Elements" ``` ### Response Example (Success) ```json [ { "itemType": "journalArticle", "title": "...", "DOI": "10.1038/..", "author": [["First", "Last"]], "source": ["Crossref"] }, { "itemType": "journalArticle", ... } ] ``` ``` -------------------------------- ### Free-text Citation Search using CrossRef API Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Performs a free-text citation search against the CrossRef REST API, returning up to 2 results. Metadata is mapped to Zotero item types via the CrossRef type translator. The search query must be URL-encoded. ```bash # Search by article title text (URL-encoded) curl "http://localhost:1970/mediawiki/The%20ENCODE%20Project%3A%20ENCyclopedia%20Of%20DNA%20Elements" ``` -------------------------------- ### Fetch Citation Data via REST API Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Use the primary endpoint to retrieve citation data by specifying the desired format and a URL-encoded identifier. Supports various identifier types and output formats. Rate limit is 1 request per second. ```bash curl "http://localhost:1970/mediawiki/https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FMain_Page" ``` ```json [{ "itemType": "webpage", "title": "Wikipedia, the free encyclopedia", "url": "https://en.wikipedia.org/wiki/Main_Page", "websiteTitle": "Wikipedia", "accessDate": "2024-01-15", "source": ["Zotero"] }] ``` ```bash curl "http://localhost:1970/zotero/10.1038%2Fnature09210" ``` ```json [{ "itemType": "journalArticle", "title": "An integrated encyclopedia of DNA elements in the human genome", "DOI": "10.1038/nature09210", "publicationTitle": "Nature", "volume": "489", "pages": "57–74", "date": "2012-09-05", "source": ["Zotero"] }] ``` ```bash curl "http://localhost:1970/bibtex/10.1038%2Fnature09210" ``` ```bibtex # @article{...} ``` ```bash curl "http://localhost:1970/mediawiki-basefields/20478883" ``` ```json [{ "itemType": "journalArticle", "title": "...", "publicationTitle": "...", "PMID": "20478883", "PMCID": "2880113", "source": ["PubMed", "Zotero"] }] ``` ```bash curl "http://localhost:1970/mediawiki/9780810935310" ``` ```bash curl "http://localhost:1970/wikibase/Q180445" ``` ```bash curl -H "Accept-Language: fr" \ "http://localhost:1970/mediawiki/https%3A%2F%2Ffr.wikipedia.org%2Fwiki%2FWikip%C3%A9dia%3AAccueil_principal" ``` ```json { "type": "https://mediawiki.org/wiki/HyperSwitch/errors/not_found", "title": "Not found", "detail": "Unable to resolve DOI ...", "uri": "/mediawiki/..." } ``` -------------------------------- ### Exporter.convertToBibtex Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Converts internal Zotero-format citation objects into BibTeX string format. ```APIDOC ## `Exporter.convertToBibtex(citation, request)` ### Description Converts internal Zotero-format citation objects into a BibTeX string. This requires Zotero to be available. ### Method Exporter method ### Parameters - **citation** (object) - The citation object in Zotero format. - **request** (object) - The request object. ### Response Example (Output Format) ```bibtex @article{Doe2023, author = {Doe, Jane}, title = {...}, journal = {...}, year = {2023}, doi = {10.x/y} } ``` ``` -------------------------------- ### Exporter.convertToZotero Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Converts internal Zotero-format citation objects into raw Zotero JSON format. ```APIDOC ## `Exporter.convertToZotero(citation, request)` ### Description Converts internal Zotero-format citation objects into raw Zotero JSON format. This is one of the supported output formats by the Exporter class. ### Method Exporter method ### Parameters - **citation** (object) - The citation object in Zotero format. - **request** (object) - The request object. ### Response Example (Output Format) ```json { "itemType": "journalArticle", "title": "...", "creators": [ { "creatorType": "author", "firstName": "Jane", "lastName": "Doe" } ], "publicationTitle": "...", "date": "...", "DOI": "..." } ``` ``` -------------------------------- ### Direct API Call using PubMed URL Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Use this endpoint to retrieve citation metadata directly by providing a PubMed URL. The URL must be URL-encoded. ```bash curl "http://localhost:1970/mediawiki/https%3A%2F%2Fpubmed.ncbi.nlm.nih.gov%2F20478883%2F" ``` -------------------------------- ### fixISBN utility Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Standalone utility function to fix ISBN strings by adding hyphens and converting them to an array. ```APIDOC ## `fixISBN(isbnObject)` ### Description Fixes ISBN strings by adding hyphens for readability and converts the ISBN to an array if it's a single string. ### Method Utility function ### Parameters - **isbnObject** (object) - An object containing the ISBN string, e.g., `{ ISBN: '9780810935310' }`. ### Response Example (Output) ```json { "ISBN": ["978-0-8109-3531-0"] } ``` ``` -------------------------------- ### Direct API Call using PMCID Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Use this endpoint to retrieve citation metadata directly using a PubMed Central ID. ```bash curl "http://localhost:1970/mediawiki/PMC2880113" ``` -------------------------------- ### Exporter Class for Format Conversion and Utilities Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt The Exporter class converts internal Zotero-format citation objects into supported output formats and handles identifier enrichment. Standalone utilities are available for fixing and normalizing dates, ISBNs, and validating ISBN strings. ```javascript const { Exporter, fixDate, fixISBN, validateISBN } = require('./lib/Exporter'); ``` ```javascript // Supported format functions (selected by citation.format): // exporter.convertToMediawiki(citation, request) → mediawiki JSON // exporter.convertToBaseFields(citation, request) → mediawiki-basefields JSON // exporter.convertToZotero(citation, request) → raw Zotero JSON // exporter.convertToBibtex(citation, request) → BibTeX string (needs Zotero) // exporter.convertToWikibase(citation, request) → Wikibase JSON with identifiers{} ``` ```javascript // Standalone utility: fix and normalize dates fixDate({ date: '2010, ©2009' }); // → { date: '2009' } fixDate({ date: '2012 Dec-Jan' }); // → { date: '2012-12' } fixDate({ date: '1660320653' }); // → { date: '2022-08-12' } (unix timestamp) ``` ```javascript // Standalone utility: fix ISBNs (add hyphens, convert to array) fixISBN({ ISBN: '9780810935310' }); // → { ISBN: ['978-0-8109-3531-0'] } ``` ```javascript // Standalone utility: validate ISBN string validateISBN('978-0-8109-3531-0'); // → '9780810935310' validateISBN('not-an-isbn'); // → false ``` ```javascript // Mediawiki format: creators converted from Zotero to 2D array // Input: { creators: [{ creatorType: 'author', firstName: 'Jane', lastName: 'Doe' }] } // Output: { author: [['Jane', 'Doe']] } (creators key removed) ``` ```javascript // Wikibase format: identifiers moved into nested object // Output: { identifiers: { doi: '10.x/y', pmid: '123', pmcid: 'PMC456', // isbn10: ['...'], isbn13: ['...'], url: 'https://...' } } ``` -------------------------------- ### Retrieve citation data Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt The primary endpoint accepts a citation format and a URL-encoded identifier (URL, DOI, ISBN, PMID, PMCID, or QID). It auto-detects the identifier type, fetches metadata from all relevant sources, and returns a structured citation object or BibTeX string. The rate limit for automated requests is 1 request per second. ```APIDOC ## GET `/{format}/{query}` — Retrieve citation data ### Description Retrieves structured citation data for a given identifier and format. Supports URLs, DOIs, ISBNs, PMIDs, PMCIDs, and QIDs. The rate limit is 1 request per second. ### Method GET ### Endpoint `/{format}/{query}` ### Parameters #### Path Parameters - **format** (string) - Required - The desired output format (e.g., `mediawiki`, `zotero`, `bibtex`, `mediawiki-basefields`, `wikibase`). - **query** (string) - Required - The URL-encoded citation identifier (e.g., URL, DOI, ISBN, PMID, PMCID, QID). ### Request Example ```bash # Fetch citation for a URL in mediawiki format curl "http://localhost:1970/mediawiki/https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FMain_Page" # Fetch citation for a DOI in zotero format curl "http://localhost:1970/zotero/10.1038%2Fnature09210" # Fetch citation for a DOI in bibtex format curl "http://localhost:1970/bibtex/10.1038%2Fnature09210" # Fetch citation for a PMID in mediawiki-basefields format curl "http://localhost:1970/mediawiki-basefields/20478883" # Fetch by ISBN in mediawiki format (requires Zotero enabled) curl "http://localhost:1970/mediawiki/9780810935310" # Fetch citation for a Wikidata QID in wikibase format curl "http://localhost:1970/wikibase/Q180445" # Fetch using Accept-Language header for localized content curl -H "Accept-Language: fr" \ "http://localhost:1970/mediawiki/https%3A%2F%2Ffr.wikipedia.org%2Fwiki%2FWikip%C3%A9dia%3AAccueil_principal" ``` ### Response #### Success Response (200 OK) - **Content-Type**: `application/json` for most formats, `application/x-bibtex` for `bibtex`. - The response is a JSON array of citation objects, or a BibTeX string. #### Response Example (application/json) ```json [ { "itemType": "webpage", "title": "Wikipedia, the free encyclopedia", "url": "https://en.wikipedia.org/wiki/Main_Page", "websiteTitle": "Wikipedia", "accessDate": "2024-01-15", "source": ["Zotero"] } ] ``` #### Response Example (application/x-bibtex) ```bibtex @article{... ``` #### Error Response (404 Not Found) - **Content-Type**: `application/problem+json` ```json { "type": "https://mediawiki.org/wiki/HyperSwitch/errors/not_found", "title": "Not found", "detail": "Unable to resolve DOI ...", "uri": "/mediawiki/..." } ``` ``` -------------------------------- ### Native HTML Scraper for Citation Metadata Source: https://context7.com/wikimedia/mediawiki-services-citoid/llms.txt Fetches a URL directly, decodes the response body, and extracts citation metadata using multiple translator passes. Falls back to schema.org for title extraction and integrates CrossRef lookup when a DOI is found. This scraper is triggered when Zotero is disabled or unavailable, or for archive.org URLs. ```javascript // Triggered when Zotero is disabled or unavailable, or for archive.org URLs. // The scraper runs these translation passes in order: // 1. bePress.js — Highwire Press & bePress metadata tags // 2. openGraph.js — og:title, og:type, og:description, og:site_name // 3. dublinCore.js — DC.title, DC.creator, DC.date, DC.identifier // 4. general.js —