-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouser_soap_example.php
33 lines (28 loc) · 1.17 KB
/
mouser_soap_example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
$wsdl = 'http://api.mouser.com/service/searchapi.asmx?WSDL';//path to wsdl file
$api_key = 'xxx-xxx-xxx';//API Key
//######################################################
$searchstring = 'V102C121A';//this can be created dynamic
//######################################################//######################################################
class Mouser_SoapClient extends SoapClient{
public function __construct(string $wsdl, array $options = []){
$options = array_merge([
'cache_wsdl' => WSLD_CACHE_NONE,
'exceptions' => true,
'soap_version' => SOAP_1_2,
'trace' => true,
], $options);
parent::__construct($wsdl, $options);
}
}
$client = new Mouser_SoapClient($wsdl);
// Header
$headerbody = array('AccountInfo'=>array('PartnerID'=> $api_key ));
$header = new SoapHeader('http://api.mouser.com/service', 'MouserHeader', $headerbody);
$client->__setSoapHeaders($header);
// Execute the SOAP request //BODY BODY BODY BODY BODY BODY BODY BODY
$result = $client->SearchByPartNumber( array('mouserPartNumber' => $searchstring) );
echo '<pre>';
print_r($result);
echo '</pre>';
?>