Browse our guides and interact with our API reference for more information about Discovery API. Try Discovery API and learn about core concepts.

 

 

Search Preview Code Samples

Use the code samples below as examples to create an application in your desired language.  The following code samples use the /searchPreviews endpoint which allows you to execute a search preview request.  Get started and begin to understand the endpoint by following the examples below in the language of your choice. 

 

Code Samples

cURL

curl -X GET \
   "https://apis.ebsco.com/discoveryapi/searchPreviews?context=cust.group.profile&query=123&lang=en-us" \
  -H "accept: application/json" \
  -H "Authorization: Bearer TOKEN"

 

Java

// Construct the client
OkHttpClient client = new OkHttpClient();

// Create the URL
HttpUrl url = new HttpUrl.Builder()
    .scheme("https")
    .host("apis.ebsco.com")
    .addPathSegment("discoveryapi")
    .addPathSegment("searchPreviews")
    .addQueryParameter("context", "cust.group.profile")
    .addQueryParameter("query", "123")
    .addQueryParameter("lang", "en-us")
    .build();

// Build the request
Request request = new Request.Builder()
    .url(url)
    .get()
    .addHeader("accept", "application/json")
    .addHeader("Authorization", "Bearer TOKEN")
    .build();
		
// Send the request
Response response = client.newCall(request).execute();
JavaScript

var host = "https://apis.ebsco.com";
var pathsega = "/discoveryapi/searchPreviews";

// Create the Request
var urlstr = host + pathsega;

var settings = {
  "async": true,
  "crossDomain": true,
  "url": urlstr,
  "method": "GET",
  "data":{ "context": "cust.group.profile", "query": "123", "lang": "en-us" },
  "headers": {
    "Authorization": "Bearer TOKEN",
    "Accept": "application/json"
  }
  "data": ""
}

// Send the Request
$.ajax(settings).done(function (response) {
  console.log(response);
});

Ruby

# Form the URL 
urlstr = File.join('https://', 'apis.ebsco.com', 'discoveryapi/searchPreviews')
url = URI(urlstr)

query = URI.encode_www_form({
    # Request parameters
    'context' => 'cust.group.profile',
    'query' => '123',
    'lang' => 'en-us'
})
if query.length > 0
  if uri.query && uri.query.length > 0
    uri.query += '&' + query
  else
    uri.query = query
  end
end

# Create the HTTP object
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

# Create the request
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer TOKEN'
request["Accept"] = 'application/json'

# Send the request
response = http.request(request)

Python

# Form the URL
url = ''.join(['/discoveryapi, '/searchPreviews'])

# Create Connection Instance
conn = http.client.HTTPSConnection("apis.ebsco.com")

# Set the Query Parameters
params = urllib.parse.urlencode({'context': 'cust.group.profile', 'query': '123', 'lang': 'en-us'})

# Create the Request Headers
headers = {
    'Authorization': "Bearer TOKEN",
    'Accept': "application/json",
    }

# Send Request  
conn.request("GET", url + '?' + params, headers=headers)