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
pageTokencontinues a search. The first request must omit the parameter; later requests pass the previous page'snextPageToken. The last page carries nonextPageToken, and a page may hold an emptystudiesarray.- All other parameters must stay identical on every page of one search.
The API exempts
countTotal,pageSize, andpageTokenfrom this rule. pageSizecaps at 1,000; larger values are silently coerced down to 1,000.0means the default of 10.totalCountappears only when the request sentcountTotal=true, and only on the first page. The client sendscountTotal=trueby default sopage.totalandcount()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
fieldsvalues fail the same way:Parameter 'fields' contains invalid field name: 'NoSuchField'. Valid names come fromclient.studies.metadata(). - Bodies of failed requests are
text/plain, not JSON. A missing study answersNCT number NCT99999999 not foundwith HTTP 404. GET /studies/{nctId}accepts any letter case and answers 200 directly. A documentedNCTIdAliasvalue redirects with HTTP 301 to the real id.
Search
query.*parameters use the Essie expression syntax and affect ranking;filter.*andpostFilter.*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.
sorttakes a comma- or pipe-separated list ofField:ascorField:descoptions.fieldsaccepts comma- or pipe-separated lists. Without it, studies come back with every field, which averages tens of kilobytes per record.
Formats
format=csvonGET /studiesreturns one page astext/csv. The CSV columns have human names (NCT Number,Study Title, ...) that differ from the JSON field names, sofields=JSON names fail the request withinvalid CSV column name. The paging token travels in thex-next-page-tokenheader and the total inx-total-count.GET /studies/{nctId}also servesformat=csv,json.zip,fhir.json, andris. 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=legacykeeps 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}wheredateis a fullyyyy-MM-ddvalue (DateStruct) or a partialyyyyoryyyy-MMvalue (PartialDateStruct). Start and completion dates are partial; posting dates are full. - The typed
Intervalstructures 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/enumsroute lists every type and value, and/studies/search-areaslists every Essie search area. - Study records commonly carry a
derivedSectionwith browse terms, and finished studies carry aresultsSection.