Eniro API

Code Snippets

Connecting and interacting with the Eniro API should be a walk in the park right from the beginning. To simplify the implementation for you, we have created some code snippets to use. These snippets are of course just meant to be inspirational examples, and using our API is in no way platform or language dependent. Since there are so many ways to connect to the API, we have started off with some of the most commonly used languages. Do you have a ready-to-use implementation snippet in a language we haven't got here yet? Send it to us, and we'll publish it here, too. With correct credits, of course.

In each example, make sure to change the profile and key values to your own. And notice that the country, search_word, geo_area and versions must be set by you. For more detailed information on this, please visit the documentation page (sign in required) where our Live module can help you format your queries correctly.

PHP

In this scenario we're requesting against Eniro API and rendering the result in an unordered list. For more information about PHP, please visit php.net.

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type"content="text/html; charset=utf-8"/>
<title>Eniro API, PHP Example</title>

</head>

<body>

<ul><?php

$url = 'https://api.eniro.com/cs/search/basic?profile=[profile]&key=[key]&country=se&version=[version]&search_word=eniro&geo_area=stockholm';

$response = file_get_contents($url);

$json = json_decode($response, true);

foreach($json['adverts'] as $item) {
echo"<li>".$item['companyInfo']['companyName'] ." (".$item['companyInfo']['orgNumber'] .")"."</li>";

}

?></ul>

</body>

</html>

jQuery (JavaScript)

In this scenario we're requesting against Eniro API and rendering the result in an unordered list. For more information about jQuery please visit jquery.com.

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type"content="text/html; charset=utf-8"/>
<title>Eniro API - jQuery Example</title>

</head>

<body>

<h1> Eniro API - jQuery Example </h1>

<ul id="company-list"> </ul>

<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>

<script>

$(document).ready(function() {
$.ajax({
url: 'https://api.eniro.com/cs/search/basic?profile=[profile]&key=[key]&country=se&version=[version]&search_word=eniro&geo_area=stockholm',
dataType: 'jsonp',
success: function(data) {
$.each(data.adverts, function() {
$("#company-list").append('<li>' + this.companyInfo.companyName + '</li>');
});
}
});
}) ;

</script>

</body>

</html>

Groovy

This code snippet retrieves the result, converts it to JSON and prints the company name for all companies. For more information about Groovy, please visit groovy.codehaus.org.

import groovy.json.*

def json = new JsonSlurper().parseText(
new URL('https://api.eniro.com/partnerapi/cs/search/basic?profile=[profile]&key=[key]&country=se&version=1.1.3&search_word=pizza').text)

json.adverts.each { println it.companyInfo.companyName }

Python

This code snippet retrieves the result, converts it to JSON and prints the company name for all companies. For more information about Python, please visit python.org.

import urllib2
res = urllib2.urlopen('https://api.eniro.com/partnerapi/cs/search/basic?profile=[profile]&key=[key]&country=se&version=1.1.3&search_word=pizza').read()
(true,false,null) = (True,False,None)
json = eval(res)
for advert in json['adverts']:
print advert['companyInfo']['companyName']

Ruby

This code snippet retrieves the result, converts it to JSON and prints the company name for all companies. For more information about Ruby, please visit ruby-lang.org.

require 'open-uri'
require 'rubygems'
require 'json'
json = JSON.parse( open('https://api.eniro.com/partnerapi/cs/search/basic?profile=[profile]&key=[key]&country=se&version=1.1.3&search_word=pizza').read )
json['adverts'].each do |advert|
puts advert['companyInfo']['companyName']
end

Java

This code snippet retrieves the result and converts it to JSON using jackson and prints the title on System.out. For more information, please visit jackson.codehaus.org.

package com.eniro.demo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.ObjectMapper;

public class EniroAPIExample {
private static ObjectMapper objectMapper = new ObjectMapper ();
public static void main(String[] args) throws JsonParseException, JsonProcessingException, IOException {
URL eniroApiUrl = new URL("https://api.eniro.com/cs/search/basic?profile=[profile]&key=[key]&country=se" +
"&version=1.1.3&search_word=pizza");


HttpURLConnection eniroUrlConn = (HttpURLConnection) eniroApiUrl.openConnection();

if (eniroUrlConn == null) {
return;
}
int respCode = eniroUrlConn.getResponseCode();

if (respCode != 200) {
return;
}

BufferedReader in = new BufferedReader(new InputStreamReader(eniroUrlConn.getInputStream(), "UTF-8"));
StringBuilder strResult = new StringBuilder();

String inputLine;
while ((inputLine = in.readLine()) != null) {
strResult.append(inputLine);
}
in.close();
JsonNode json = objectMapper.readTree(objectMapper.getJsonFactory().createJsonParser(strResult.toString()));
System.out.println("Title: "+json.path("title"));
}
}

Share ideas and improvements?

If you have your own ready-to-use implementation snippet in a language we haven't got here or any issue/suggestion you want to share, please contact us.

forward back

We're Using Eniro API

  • Kvasir

    Multi source search engine for web, images, companies and news

  • ServiceFinder

    Helps service providers and service
    buyers/consumers to find each other online

  • Bloggerfy

    Scandinavia's fastest growing blog rating Site

  • Gule Sider on iPhone

    One of the largest yellow pages, white pages
    and map provider in Norway

  • Krak on iPhone

    The largest yellow pages and white pages
    provider in Denmark

Please wait..
Oops! There was a problem, please try again later.