Skip to content

ClinicalTrials.gov upstream quirks

Observed behavior of the ClinicalTrials.gov Data API v2 that shapes the client. The OpenAPI 3.0 document the API publishes lives at https://clinicaltrials.gov/api/oas/v2.

Paging

  • pageToken continues a search. The first request must omit the parameter; later requests pass the previous page's nextPageToken. The last page carries no nextPageToken, and a page may hold an empty studies array.
  • All other parameters must stay identical on every page of one search. The API exempts countTotal, pageSize, and pageToken from this rule.
  • pageSize caps at 1,000; larger values are silently coerced down to 1,000. 0 means the default of 10.
  • totalCount appears only when the request sent countTotal=true, and only on the first page. The client sends countTotal=true by default so page.total and count() report totals.

Requests and errors

  • The API rejects unknown query parameters with HTTP 400 and a plain-text body: `bogusParam` is unknown parameter. There is no lenient mode.
  • Unknown fields values fail the same way: Parameter 'fields' contains invalid field name: 'NoSuchField'. Valid names come from client.studies.metadata().
  • Bodies of failed requests are text/plain, not JSON. A missing study answers NCT number NCT99999999 not found with HTTP 404.
  • GET /studies/{nctId} accepts any letter case and answers 200 directly. A documented NCTIdAlias value redirects with HTTP 301 to the real id.
  • query.* parameters use the Essie expression syntax and affect ranking; filter.* and postFilter.* parameters do not. The two filter parameter families have the same effect when no aggregation runs.
  • If every query parameter holds only NCT ids, filters are ignored.
  • sort takes a comma- or pipe-separated list of Field:asc or Field:desc options.
  • fields accepts comma- or pipe-separated lists. Without it, studies come back with every field, which averages tens of kilobytes per record.

Formats

  • format=csv on GET /studies returns one page as text/csv. The CSV columns have human names (NCT Number, Study Title, ...) that differ from the JSON field names, so fields= JSON names fail the request with invalid CSV column name. The paging token travels in the x-next-page-token header and the total in x-total-count.
  • GET /studies/{nctId} also serves format=csv, json.zip, fhir.json, and ris. These are alternate renderings of the same record; the client wraps the JSON form.
  • markupFormat=markdown (the default) renders markup-type fields such as eligibility criteria as CommonMark; markupFormat=legacy keeps the classic PRS line markup. The parameter only applies to JSON.
  • The classic API's XML and CSV bulk endpoints do not exist in v2.

Data model

  • Date values arrive as typed structures: {date, type} where date is a full yyyy-MM-dd value (DateStruct) or a partial yyyy or yyyy-MM value (PartialDateStruct). Start and completion dates are partial; posting dates are full.
  • The typed Interval structures of the classic API have no counterpart in the v2 document or in live records.
  • Field values use UPPER_SNAKE enumerations (RECRUITING, PHASE3, ACTUAL); the /studies/enums route lists every type and value, and /studies/search-areas lists every Essie search area.
  • Study records commonly carry a derivedSection with browse terms, and finished studies carry a resultsSection.