UCUM Web Service

This is a set of web services (APIs) for programs to use when working with units from the Unified Code for Units of Measure (UCUM) system. These are the same APIs as those that are running at xml4pharmaserver.com, and are based on that website's web service code which has been donated to the U.S. National Library of Medicine by FH-Prof. Jozef Aerts and Mr. Milos Ilic MSc, Institute of eHealth, University of Applied Sciences FH Joanneum in Graz Austria.

Currently, three web services are available:

General notes:

UCUM Service version: 3.1.0 (changes)


Through the UCUM "ucum-essence.xml" file it is possible to do unit conversions without the need of conversion tables.
An algorithm has been developed that takes any unit in UCUM notation and decomposes it (using "cascading") into the base units (m,s,g,rad,K,cd,rad,mol), allowing one to do unit conversion calculations.
This algorithm has now also been implemented in this RESTful web service. It is also used to validate whether a string corresponds to a valid UCUM unit (i.e. is a valid UCUM notation).

UCUM Unit Conversion web service

Disclaimer: Before relying on the unit conversions produced by this service it is your obligation to perform your own tests to verify that the results are sufficiently accurate for your purposes.

The principles of the web service are the following:

So the HTTP request format is essentially:
when the source quantity = 1 (the default)

Depending on what requested MIME type your HTTP request has (XML, JSON, text), you will receive either XML, JSON or simple text.
In the latter case, you will get a simple string like:

1.0 [in_i] = 2.54 cm

To select between XML, JSON, and text output, one specifies an "Accept" header in the HTTP request, i.e., "Accept: application/xml", "Accept: application/json", or "Accept: text/plain". The default output is in XML, which for this example provides the structure below.

<UCUMWebServiceResponse ServerDateTime="2017-12-26T20:15:48">

Simple examples (all for request type "text")

To convert 1 inch (UCUM notation [in_i]) to centimeter (cm), use:
or: https://ucum.nlm.nih.gov/ucum-service/v1/ucumtransform/from/[in_i]/to/cm
(as 1 is the default for the value to be converted).
Result: 1.0 [in_i] = 2.54 cm

To convert 3.5 foot (UCUM notation [ft_i] to micrometer (um), use:
Result: 3.5 [ft_i] = 1066800.0 um

To convert 1 apothecary ounces (UCUM notation: [oz_ap]) to grams (g), use:
Result: 1.0 [oz_ap] = 31.103477 g

To convert 2.5 pounds per square inch (UCUM notation: [psi]) into millimeter mercury column (UCUM notation: mm[Hg]) use:
Result: 2.5 [psi] = 129.28769 mm[Hg]

Somewhat more difficult examples

Suppose you have a flow rate expressed in US gallons per minutes (UCUM notation: [gal_us]/min), and want to convert that to liters per hour (UCUM notation: l/h or L/h - both are valid). Use:
Result: 1.0 [gal_us]/min = 227.12471 l/h

In order to convert "millimeter of mercury" (UCUM notation mm[Hg]) into its base components, which is kg/m.s-2 (kilogram per meter times square seconds), use:
Result: 1.0 mm[Hg] = 133.322 kg/m.s-2

Non-matching properties

When trying to convert between units for which the properties don't match (e.g. weight to time), you will get an error message.
For example for kg (kilograms) to min (minutes), when you use:
you will get the error message: Error: Source and Target unit do not seem to belong to the same property
Properties must also match for complex expressions (e.g., kg/m.s-2), for which the converting engine breaks the expression down to the base units, and compares the exponents on the base units between source and target.

Conversions using moles

This section is about conversions where "mol" appears in both the target and soure unit. For conversions from mol to other types of units, see below.

Essentially, "mol" is not a unit, it is a number. So 1 mol of cows is 6.022E23 cows.
However, as people are used to working with mole as if it were a unit, "mol" was implemented as a base unit. So if, for example, we want to do a concentration conversion such as "convert 1 mol per cubic inch (UCUM notation: [in_i]3) to mol/L", we use:
Result: 1.0 mol/[in_i]3 = 61.023744 mol/L

One can also do more complex unit conversions using "mol", such as between "PK units" that have been published by CDISC
For example, if you want to do the conversion between "h.pmol/l" (picomol-hours per liter) to "min.umol/ml" (micromol-minutes per cubic meter), use:
Result: 1.0 h.pmol/l = 0.06 min.umol/m3
This works, as both "l" (liter) and "m3" are volumes.

Conversions between moles, mass, and equivalents

Conversions between units involving moles, mass, and equivalents ("eq") can be done with some limitations:

For mass-mole conversions when the molecular weight is known, include it at the end of the URL, after "MOLWEIGHT", like:

For mass-mole conversions when the the LOINC code is known, include it at the end of the URL, after "LOINC", like:

For conversions between equivalents and either mass or moles, also supply the LOINC code at the end, as above. For example:

One can also use parentheses (but no nested parentheses yet), for example:



In some cases, you might want to use annotations, for example to express "mol of creatinine".
You can do so, as long as there is a match between the annotations of the source with the annotations at the target side. If this is not the case, you will obtain an error message saying: ERROR: annotations mismatch between source and target

A valid web service request is, for example:
Result: 1.0 mol{creatinine}/l = 0.016387064 mol{creatinine}/[in_i]3


(The following example is courtesy of Jozef Aerts of XML4Pharma.)

One of the misconceptions (within CDISC) about UCUM is that it would not be useful for units of the preclinical world (such as CDISC-SEND submissions). The contrary is true! UCUM brings order in units for animal and other preclinical studies. For example for the CDISC "PKUNIT" codelist (NCI C85494) contains almost 300 terms, with CDISC adding new ones each time a new version is published. As the number of combinations is in principle inifinite, this list will grow and grow.
Furthermore, the CDISC codelist does not provide a mechanism for unit conversions. It does not, for example, allow one to calculate how many "(L/h)/m2" go into "(L/min)/cm2".
For "PKUNIT", no codelist is necessary: UCUM solves everything!

Let us take a somewhat more typical SEND example: We have chickens that drink water, and measure how much water they consume as function of the amount of space they have, amount of food, and time.
We however have one group in the US that measures this using gallons, square feet, ounces of food, and hours. In Europe however, the same measurement is made using liters, square meters, grams of food, and days.
With UCUM, this would be expressed as:

UCUM notation for the measurement in the US: [us_gal]{waterconsumption}/([ft_i]2.{chicken}.[oz_av]{food}.h)
UCUM notation for the measurement in Europe: l{waterconsumption}/(m2.{chicken}.g.{food}.d)

The conversion factor can easily be obtained using our RESTful web service:


Current limitations

Currently we still have following limitations (but are working on removing them):

If you find any other limitations or errors, please report them.

The UCUM unit validity service

In some cases you (or your application) simply wants to check whether a string corresponds to a valid UCUM string/unit.
This can easily be done by using the "isValidUCUM" web service.

This web service is very simple to use:

Because the output is so simple, there are no alternative formats (XML and JSON) for this service, unlike the others.


The UCUM unit to base units service

Request string:

For example, if you don't know the base units of "circular mil" (UCUM notation "[cml_i]"), you submit:

Or for "gallon per square foot":


<UCUMWebServiceResponse ServerDateTime="2017-12-26T23:05:32">
      <BaseUnit Name="m" Exponent="1"/>

When you think about it, it is clear: "gallon" is a volume (base unit: m3) and "square foot" is an area (base unit: m2), so, "gallon per square foot" reduces to "m" (exponent=1) and the "conversion" factor is 0.0407.

Output can also be requested in JSON or a plain text format, again by specifying an "Accept" header in the HTTP request, as mentioned above.

Another example is breaking down mm[Hg] to the base units:


Which returns (here as XML):

<UCUMWebServiceResponse ServerDateTime="2017-12-26T23:08:27">
      <BaseUnit Name="s" Exponent="-2"/>
      <BaseUnit Name="g" Exponent="1"/>
      <BaseUnit Name="m" Exponent="-1"/>

Essentially stating that 1 mm[Hg] = 133322 g.s-2.m-1 (in UCUM notation, or 133322 g/(m*s2) using standard operator symbols).

Also, note that the entries under "ResultBaseUnitList" can be used for easily treating the result or for chaining

Note on special units: For "special" UCUM units, which are units that require some formula to be converted to base units (such [degF] to K), the result quantity is not included to avoid the misunderstaning that it could be used as a scaling factor for converting other amounts of the source unit. Also, for the plain text output format, the normal '=' sign between the source and base unit string is replaced with '~', for the same reason.

Special character encoding

Not all browsers correctly encode the special characters "[", "]", "{" and "}" when doing the HTTP request. So if you copy-paste the listed URLs, you may need to replace following special characters: In applications, this might be taken care of by the framework that you use (e.g. JAX-RS), but if not, look for an API that will "URL encode" the unit strings.

When using the browser, also ensure that it accepts XML, and displays it as such, i.e. that it does not try to "style" it. For example, some issues have been reported with Firefox with the Skype plugin.

Use of these web services

Although one can use these web services in the browser (you probably already discovered that), this is not the primary use of RESTful web services. This kind of web service is meant to be used in applications.

You are invited to use these web services in your pilot and production applications, taking the following into account: