def europepmc_api_to_publication(ext_id, id_type):
    # https://europepmc.org/docs/EBI_Europe_PMC_Web_Service_Reference.pdf
    assert id_type in Publication.ID_TYPES, "id_type must be in {}".format(Publication.ID_TYPES.keys())
    # Request the data
    if id_type == "pmcid":
        url = 'https://www.ebi.ac.uk/europepmc/webservices/rest/search?query=PMCID:PMC{}&resulttype=core&format=json'
        url = url.format(ext_id)
    elif id_type == "doi":
        url = "https://www.ebi.ac.uk/europepmc/webservices/rest/search?query=DOI:%22{}%22&resulttype=core&format=json"
        url = url.format(ext_id)
    elif id_type == "pmid":
        url = 'https://www.ebi.ac.uk/europepmc/webservices/rest/search?query=EXT_ID:{}%20AND%20SRC:MED&resulttype=core&format=json'
        url = url.format(ext_id, id_type)
    else:
        raise ValueError("id_type must be in {}".format(Publication.ID_TYPES.keys()))
    headers = {
        'User-Agent': config['USER_AGENT_DEFAULT']
    }
    response = requests.get(url, headers=headers)
    response.raise_for_status()
    d = response.json()
    if d['hitCount'] != 1:
        raise ValueError("No results")
    article = d['resultList']['result'][0]

    p = Publication()
    p.ref_url = url
    p.source = "europepmc"
    original_title = article['title']
    # to remove trailing dot
    # to exclude '...' and abbreviations such as U.S.A.
    p.title = original_title
    if original_title[-1] == '.' and original_title[-3] != '.':
        p.title = original_title[:-1]  # drop the trailing dot

    authors = []
    authorlist = article["authorList"]["author"]
    for author in authorlist:
        full_name = None
        if 'firstName' in author and 'lastName' in author:
            full_name = author['firstName'] + ' ' + author['lastName']
        elif 'fullName' in author:
            full_name = author['fullName']
        elif 'collectiveName' in author:
            full_name = author['collectiveName']
        else:
            msg = "unknown author: {}".format(author)
            p.warnings.append(msg)
        # orcids
        orcid = None
        if 'authorId' in author:
            if author['authorId']['type'] == "ORCID":
                orcid = author['authorId']['value']
        authors.append({'full_name': full_name, 'orcid': orcid})
    p.authors = authors
    p.publication_date = du.parse(article['firstPublicationDate'])
    p.volume = article['journalInfo'].get('volume')
    p.issue = article['journalInfo'].get('issue')
    p.pages = article.get('pageInfo')

    p.ids = dict()
    p.ids['doi'] = article.get('doi')
    p.ids['pmid'] = article.get('pmid')
    p.ids['pmcid'] = article.get('pmcid', '').replace("PMC", "")

    if 'pageInfo' in article:
        # according to documentation, they should be in the form : 145-178, but also "D36-42" has been in the responses
        try:
            pageString = article['pageInfo']
            pageStringParts = pageString.split('-')
            pageStartString = pageStringParts[0]
            if pageStartString.startswith('D'):
                pageStartString = pageStartString[1:]
            pageStart = int(pageStartString)
            pageEndString = pageStringParts[1]
            pageEnd = int(pageEndString)
            pages = pageEnd - pageStart + 1
            p.number_of_pages = pages
        except Exception:
            pass
    """
    # this is probably a list, and we need to be able to look up a qid from "NCI NIH HHS" for example...
    if "grantsList" in article and "grant" in article['grantsList'] and "agency" in article['grantsList']["grant"]:
        p.sponsor = article['grantsList']["grant"]["agency"]
    """

    # get the type of publication
    # if not told that it is a research-article, we will make it a general publication
    isScientificArticle = False
    if 'pubTypeList' in article:
        pubtypes = article['pubTypeList']['pubType']
        if isinstance(pubtypes, str):
            if pubtypes == 'research-article':
                isScientificArticle = True
        elif isinstance(pubtypes, list):
            if 'research-article' in pubtypes:
                isScientificArticle = True
    if isScientificArticle:
        p.instance_of = "scientific_article"
    else:
        p.instance_of = "publication"
        p.warnings.append("unknown publication type, assuming publication")

    issns = []
    if 'issn' in article['journalInfo']['journal']:
        issns.append(article['journalInfo']['journal']['issn'])
    elif 'essn' in article['journalInfo']['journal']:
        issns.append(article['journalInfo']['journal']['essn'])
    else:
        msg = "unknown journal: {}".format(article['journalInfo']['journal'])
        p.warnings.append(msg)
    p.published_in_issn = issns

    return p
# this is probably a list, and we need to be able to look up a qid from "NCI NIH HHS" for example...
    if "grantsList" in article and "grant" in article['grantsList'] and "agency" in article['grantsList']["grant"]:
        p.sponsor = article['grantsList']["grant"]["agency"]