cog-uk.js
v9.0.0
Published
## Create an API client
Downloads
3
Readme
cog-uk.js
Create an API client
const coguk = require("cog-uk.js");
const username = "test-username";
const token = "973db08f-8d68-4434-96cd-068d66d1dfa4";
const client = coguk(username, token);
Authenticate credentials
const ok = await client.authenticate();
if (ok) {
// Valid credentials
}
else {
// Invalid credentials
}
Submit Biosample
const sample = {
"adm1": "UK-ENG",
"central_sample_id": "BIRM-XXXXX",
"collection_date": "2020-03-22",
"source_age": 29,
"source_sex": "M",
"secondary_accession": "EPI_ISL_XXXXXX",
"secondary_identifier": "hCov-19/England/Patient0/2020",
"adm2": "WEST MIDLANDS",
"collecting_org": "Queen Elizabeth Hospital Birmingham",
"root_sample_id": "H20XXXXXXXX",
"sample_type_collected": "swab",
"sender_sample_id": "QELAB-01",
"swab_site": "nose",
// See https://docs.covid19.climb.ac.uk/majora/add_sample#reference for full list of biosample fields
"library_name": "BIRM-LIBRARY-20200322",
// See https://docs.covid19.climb.ac.uk/majora/add_library#reference for full list of library fields
"run_name": "BIRM-my_first_run",
// See https://docs.covid19.climb.ac.uk/majora/add_sequencing#reference for full list of sequencing fields
};
const results = await client.submit(validSample);
results
:
{
"success": true,
"status": "updated",
"detailedMessages": {},
"messages": {},
"error": null
}
Submit an invalid Biosample
const sample = {
"adm1": "England",
};
const results = await client.submit(validSample);
results
:
{
"success": false,
"status": "ignored",
"detailedMessages": {
"central_sample_id": [
{
"message": "This field is required.",
"code": "required",
"source": "biosample"
}
],
"adm1": [
{
"message": "Select a valid choice. England is not one of the available choices.",
"code": "invalid_choice",
"source": "biosample"
}
],
"received_date": [
{
"message": "You must provide a received date for samples without a collection date",
"code": "",
"source": "biosample"
}
]
},
"messages": {
"central_sample_id": "This field is required.",
"adm1": "Select a valid choice. England is not one of the available choices.",
"received_date": "You must provide a received date for samples without a collection date"
},
"error": "Errors in the following fields: central_sample_id, adm1, received_date"
}