European Commission logo
KnowSDGs

SDG Mapper API

Welcome to the SDG Mapper API

POST /api/rest/mappingdata

Returns SDGs, Targets and Indicators detected data.

Returns the SDGs, Targets and Indicators detected in the input text, in the form of JSON objects. The JSON response contains linked data in JSON-LD format

Response (Status 200)

Returns a list of SDGs, Targets and, optionally, Indicators

Example

{
  "@context": {
    "sdgo": "http://metadata.un.org/sdg/ontology#",
    "description": "https://schema.org/description",
    "name": "https://schema.org/name",
    "n_occurrences": "https://knowsdgs.jrc.ec.europa.eu/vocab/n_occurrences",
    "relevance": "https://knowsdgs.jrc.ec.europa.eu/vocab/relevance",
    "children": "https://json-schema.org/draft/2020-12/schema#children",
    "api_version": "https://schema.org/version",
    "id": "@id",
    "type": "@type"
  },
  "type": "https://schema.org/dataset",
  "description": "The SDG Mapper API, developed by the JRC and DG INTPA, enables users to submit text (in any official EU language) and receive SDGs, Targets and Indicators detected data in the form of JSON objects.",
  "children": [{
      "id": "https://unstats.un.org/SDGAPI/v1/sdg/Goal/1/Target/List",
      "type": "sdgo:Goal",
      "name": "SDG 1",
      "n_occurrences": 3,
      "relevance": "75.0%",
      "children": [{
        "id": "https://unstats.un.org/SDGAPI/v1/sdg/Target/1.5/Indicator/List",
        "type": "sdgo:Target",
        "name": "Target 1.5",
        "n_occurrences": 3,
        "children": [{
          "id":"https://unstats.un.org/SDGAPI/v1/sdg/Indicator/1.5.1/Series/List",
          "type":"sdgo:Indicator",
          "name":"Indicator 1.5.1"
        }]
      }]
    },
    {
      "id": "https://unstats.un.org/SDGAPI/v1/sdg/Goal/3/Target/List",
      "type": "sdgo:Goal",
      "name": "SDG 3",
      "n_occurrences": 1,
      "relevance": "25.0%",
      "children": [{
        "id": "https://knowsdgs.jrc.ec.europa.eu/vocab/SDG3_undetected_target",
        "type": "sdgo:Target",
        "name": "undetected_target",
        "n_occurrences": 1
      }]
    }
  ],
  "api_version": "v1"
}

Response Content Type: application/json

Parameters
Parameter Value Description Parameter Type Data Type
X-Api-Key YOUR API KEY (required) Your API Key
Click here to get API access and key
header string
input_text Text to process
Limited to 3.5 MB of text data
formData string
indicators Includes indicators in response
Default: 'False'
Accepted values: 'True', 'False'
formData string
source_language Language code for the text to process
Default: 'en'
Check the language codes table below
formData string
Response Messages
HTTP Status Code Reason
204 Successful request with no results
400 Missing input_text parameter
403 Bad input parameter: the 'input_text' is limited to 3528000 bytes (3.5 MB)
403 Bad input parameter: the 'indicators' parameter accepts only values 'True' and 'False'
403 Bad input parameter: invalid source language
403 Bad input parameter: Cannot execute mapping command
500 Your request has timed out. Send your request again
Language Codes (ISO 639-1)
Language Code
Bulgarian bg
Croatian hr
Czech cs
Danish da
Dutch nl
English en
Estonian et
Finnish fi
French fr
German de
Greek el
Hungarian hu
Irish ga
Italian it
Latvian lv
Lithuanian lt
Maltese mt
Polish pl
Portuguese pt
Romanian ro
Slovak sk
Slovenian sl
Spanish es
Swedish sv
Sample Python Code
import requests, json

doc_texts = "YOUR_TEXT_TO_SUBMIT"
if len(doc_texts) > 3528000:
  print("Text too long")
else:
  url = "https://knowsdgs.jrc.ec.europa.eu/"

  headers = {"Content-Type": "application/json", "X-Api-Key": "YOUR_API_KEY"}
  r = requests.post(url + "api/rest/mappingdata", headers=headers, json={"input_text": doc_texts})
  #r = requests.post(url + "api/rest/mappingdata", headers=headers, json={"input_text": doc_texts, "indicators": "True", "source_language": "LANG_CODE"})
  try:
    print(json.loads(r.text))

    un_url = json.loads(json.loads(r.text)["data"][0])["children"][0]["id"]
    print(requests.get(un_url).json()[0]["title"])
  except:
    print(r.status_code)
Sample NodeJs Code

npm install node-fetch@2

#!/usr/bin/env node

const fetch = require("node-fetch");

let doc_texts = "YOUR_TEXT_TO_SUBMIT";
if (doc_texts.length > 3528000) {
  console.log("Text too long");
} else {
  const url = "https://knowsdgs.jrc.ec.europa.eu/";

  let postData = JSON.stringify({"input_text": doc_texts});
  //let postData = JSON.stringify({"input_text": doc_texts, "indicators": "True", "source_language": "LANG_CODE"});

  fetch(url + "api/rest/mappingdata", {
    method: "post",
    body: postData,
    headers: {"Content-Type": "application/json", "X-Api-Key": "YOUR_API_KEY"},
  }).then(res => {
    if (res.status == 200) {
      return res.json();
    } else {
      return res.status;
    }
  }).then(json => {
    console.log(json);

    let un_url = JSON.parse(json["data"][0])["children"][0]["id"];
    fetch(un_url)
      .then(res => res.json())
      .then(json => console.log(json[0]["title"]));
  });
}