How to Authenticate with D&B Direct API Web Service
Step 1: First you have to create an account in D&B using this online form http://developer.dnb.com/register-v2 and get your Username and Password.
Step 2: You can get connected with D&B direct api via SOAP and REST api.
Soap API Call Example:
To get connected with D&B api using soap client call. Follow the below php code.
<?php
$soap_client = new SoapClient(NULL,array('uri' =>'http://api.dnbdirectapps.com/dev/DnBAPI-15/dnbAPI/dnbAPI.wsdl','username' => '********','password' => '********','location' => 'test'));
//$soap_client = new SoapClient('http://ws-spr1.spexlive.net/service/soap/catalog?appId=226175');
echo "<pre>";
$getcat=$soap_client->GetCompanyDetailRequest();
print_r($getcat);
var_dump($soap_client);
?>After hit this code you can company detail request. As i mentioned this api function in soap client request.
Rest API Example:
To get connected with D&B Direct Rest api, You need an authentication Token to access it. First get the New Token using this POST request.
POST https://maxcvservices.dnb.com/Authentication/V2.0/ x-dnb-user: MyUsername x-dnb-pwd: MyPassword
After that you Success result with new auth token. Use token in below Curl code to get data from D&B Direct api.
<?php
$api_url='https://maxcvservices.dnb.com/V2.0/organizations/804735132/products/BIR?ProductFormatPreferenceCode=15106';
$dnbch = curl_init();
curl_setopt( $dnbch, CURLOPT_URL, $api_url );
curl_setopt( $dnbch, CURLOPT_HTTPHEADER, array ('Accept: application/json', 'Content-Length: 0') );
curl_setopt( $dnbch, CURLOPT_VERBOSE, 0 );
curl_setopt( $dnbch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt( $dnbch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $dnbch, CURLOPT_USERPWD, "Authorization:******New Token Here*****" );
curl_setopt( $dnbch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $dnbch, CURLOPT_RETURNTRANSFER, 1 );
$response = curl_exec( $dnbch );
$result = json_decode($response);
echo "<pre>";
print_r($result);
?>
Hello,
I am still working on connecting to the D&B soap api, do you have anything else you can add? I am new to programming and SOAP is harder than I thought.
Thanks
Caitlin
Hi Caitlin,
Soap programming for d&b is quite simple. use this soap code to get connected.
array(
‘method’=>’GET’,
‘ignore_errors’ => true,
‘header’=>”API-KEY:****Use API Key Here*****\r\nusername:***Username**\r\npassword:***Password**”,
)
);
$fp = fopen(‘http://dnbdirect-api.dnb.com/DnBAPI-15/rest/company/060704780’, ‘rb’, false, stream_context_create($opts));
$response = stream_get_contents($fp);
print $response;
?>
no one code is working for me, how i get API-KEY. I have only username and password.
And what is the website url where i have check given username and password given by client.
Hi Steve, You can get access token from using username and password. Just follow these steps : https://docs.dnb.com/direct/2.0/en-US/quick-rest-API
Send POST request using username and password to get token value.
Thanks
Hi,
How to get a list of companies details using this Api?