POST lookup/id

Find the species and database for several identifiers. IDs that are not found are returned with no data.

Parameters

Required

No required parameters

Optional

NameTypeDescriptionDefaultExample Values
callback String Name of the callback subroutine to be returned by the requested JSONP response. Required ONLY when using JSONP as the serialisation method. Please see the user guide. - randomlygeneratedname
db_type String Restrict the search to a database other than the default. Useful if you need to use a DB other than core - core
otherfeatures
expand Boolean(0,1) Expands the search to include any connected features. e.g. If the object is a gene, its transcripts, translations and exons will be returned as well. 0 -
format Enum(full,condensed) Specify the formats to emit from this endpoint full -
object_type String Filter by feature type - gene
transcript
species String Species name/alias. Causes problems if the species doesn't match the identifiers in the POST body. - homo_sapiens
human

Message

Content-typeFormatExample
application/json{ "ids": array }{ "ids" : ["ENSG00000157764", "ENSG00000248378" ] }

Example Requests

/lookup/id


{ "ids" : ["ENSG00000157764", "ENSG00000248378" ] }
        
use strict;
use warnings;

use HTTP::Tiny;

my $http = HTTP::Tiny->new();

my $server = 'http://rest.ensembl.org';
my $ext = '/lookup/id';
my $response = $http->request('POST', $server.$ext, {
  headers => { 
  	'Content-type' => 'application/json',
  	'Accept' => 'application/json'
  },
  content => '{ "ids" : ["ENSG00000157764", "ENSG00000248378" ] }'
});

die "Failed!\n" unless $response->{success};


use JSON;
use Data::Dumper;
if(length $response->{content}) {
  my $hash = decode_json($response->{content});
  local $Data::Dumper::Terse = 1;
  local $Data::Dumper::Indent = 1;
  print Dumper $hash;
  print "\n";
}

import requests, sys

server = "http://rest.ensembl.org"
ext = "/lookup/id"
headers={ "Content-Type" : "application/json", "Accept" : "application/json"}
r = requests.post(server+ext, headers=headers, data='{ "ids" : ["ENSG00000157764", "ENSG00000248378" ] }')

if not r.ok:
  r.raise_for_status()
  sys.exit()

decoded = r.json()
print repr(decoded)

import requests, sys

server = "http://rest.ensembl.org"
ext = "/lookup/id"
headers={ "Content-Type" : "application/json", "Accept" : "application/json"}
r = requests.post(server+ext, headers=headers, data='{ "ids" : ["ENSG00000157764", "ENSG00000248378" ] }')

if not r.ok:
  r.raise_for_status()
  sys.exit()

decoded = r.json()
print(repr(decoded))

require 'net/http'
require 'uri'

server='http://rest.ensembl.org'
path = '/lookup/id'

url = URI.parse(server)
http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(path, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
request.body = '{ "ids" : ["ENSG00000157764", "ENSG00000248378" ] }'

response = http.request(request)

if response.code != "200"
  puts "Invalid response: #{response.code}"
  puts response.body
  exit
end


require 'rubygems'
require 'json'
require 'yaml'

result = JSON.parse(response.body)
puts YAML::dump(result)

import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Reader;
import java.io.DataOutputStream;


public class EnsemblRest {

  public static void main(String[] args) throws Exception {
    String server = "http://rest.ensembl.org";
    String ext = "/lookup/id";
    URL url = new URL(server + ext);

    URLConnection connection = url.openConnection();
    HttpURLConnection httpConnection = (HttpURLConnection)connection;
    
    String postBody = "{ \"ids\" : [\"ENSG00000157764\", \"ENSG00000248378\" ] }";
    httpConnection.setRequestMethod("POST");
    httpConnection.setRequestProperty("Content-Type", "application/json");
    httpConnection.setRequestProperty("Accept", "application/json");
    httpConnection.setRequestProperty("Content-Length", Integer.toString(postBody.getBytes().length));
    httpConnection.setUseCaches(false);
    httpConnection.setDoInput(true);
    httpConnection.setDoOutput(true);

    DataOutputStream wr = new DataOutputStream(httpConnection.getOutputStream());
    wr.writeBytes(postBody);
    wr.flush();
    wr.close();
    

    InputStream response = connection.getInputStream();
    int responseCode = httpConnection.getResponseCode();

    if(responseCode != 200) {
      throw new RuntimeException("Response code was not 200. Detected response was "+responseCode);
    }

    String output;
    Reader reader = null;
    try {
      reader = new BufferedReader(new InputStreamReader(response, "UTF-8"));
      StringBuilder builder = new StringBuilder();
      char[] buffer = new char[8192];
      int read;
      while ((read = reader.read(buffer, 0, buffer.length)) > 0) {
        builder.append(buffer, 0, read);
      }
      output = builder.toString();
    } 
    finally {
        if (reader != null) try {
          reader.close(); 
        } catch (IOException logOrIgnore) {
          logOrIgnore.printStackTrace();
        }
    }

    System.out.println(output);
  }
}

library(httr)
library(jsonlite)
library(xml2)

server <- "http://rest.ensembl.org"
ext <- "/lookup/id"
r <- POST(paste(server, ext, sep = ""), content_type("application/json"), accept("application/json"), body = '{ "ids" : ["ENSG00000157764", "ENSG00000248378" ] }')

stop_for_status(r)

# use this if you get a simple nested list back, otherwise inspect its structure
# head(data.frame(t(sapply(content(r),c))))
head(fromJSON(toJSON(content(r))))

curl 'http://rest.ensembl.org/lookup/id' -H 'Content-type:application/json' \
-H 'Accept:application/json' -X POST -d '{ "ids" : ["ENSG00000157764", "ENSG00000248378" ] }'

wget -q --header='Content-type:application/json' --header='Accept:application/json' \
--post-data='{ "ids" : ["ENSG00000157764", "ENSG00000248378" ] }' \
'http://rest.ensembl.org/lookup/id'  -O -

Resource Information

MethodsPOST
Response formatsjson
jsonp
Maximum POST size1000