PDA

View Full Version : File type for SOAP Requests


Iceman
01-05-07, 14:06
Hi,
I am just trying to get to grips with the API but have limited experience with web services. I have read the documents but I don't seem to have found an example request. What I have got so far after reading about SOAP & WSDL is the following code but I don't know what to do with it. Do save it in a file with certain file extension and have it as an include file in PHP?

Can someone point me to an example of an API request please?

Content-Type: application/soap+xml; charset=utf-8
Content-Length: 250

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Header xmlns:m="http://api.productserve.com/v1/ProductServeService?wsdl">
<m:ild>123</m:ild>
<m:sPassword>mysecretpassword</m:sPassword>
<m:sType>Test</m:sType> ? What is required here?
...
</soap:Header>

<soap:Body xmlns:m="http://api.productserve.com/v1/ProductServeService?wsdl">
<m:SearchProduct
<m:Keyword>Canon Camcorder</m:Keyword>
</m:SearchProduct>

<soap:Fault>
...
...
</soap:Fault>
</soap:Body></soap:Envelope>

Iceman
01-05-07, 14:43
I shall go & buy a book on SOAP & Webservices but would appreciate if someone can explain what the sType parameter is please.

authcode
01-05-07, 15:05
Hi Iceman,

I started with good PHP and HTML experience but didn't have a clue about SOAP and web services either. I did two things to get started:
1. I printed off the ShopWindow API Technical Spec Doc (http://www.shopwindowforum.com/attachment.php?attachmentid=3&d=1174904455) which is invaluable.
2. I started hacking the SW Client install and stripped it down to the bare minimum to see what actually retrieved the data. This basically involves following the chain of includes and stripping out all the SMARTY stuff (which I've never used before either).
The client install has API classes to handle all the soap requests so you don't need to actually understand SOAP - you just call the the API clients with parameters like you would a function.
I started with something like this:

<?php
# DETERMINE SYSTEM SETTINGS, depending on OS
if (!defined('HOME_PATH')) {
$sPath= dirname(__FILE__).DIRECTORY_SEPARATOR;
define('HOME_PATH', $sPath);
}

// USER DETAILS
define('USER_ID', '<YOUR USER ID>');
define('USER_PASS', '<YOUR USER PASSWORD>');

// LOAD CLASSES
require_once('includes'.DIRECTORY_SEPARATOR.'class es'.DIRECTORY_SEPARATOR.'class.api_client.php');

//new client
$oClient = new api_client();

//set the paremeters
$aHotPicksParams = array('iCategoryId'=> 0, 'sSort'=> 'random', 'iLimit'=> 10, 'iOffset'=> 0);

//make the SOAP call
$oHotPicks = $oClient->call('getHotPickProductList', $aHotPicksParams);

//get the products array
$aProducts = $oHotPicks->getHotPickProductListReturn;

//print each product name to the page
foreach ($aProducts as $oProduct) {
echo $oProduct->sName;
echo '<br />';
}
?>


paste this code into a PHP file and replace the user ID and password with your own which can be found in the client global.inc.php that you downloaded. Also make sure that the client 'includes' directory exists in the same directory as this PHP file. If you get error messages it's most like to do with incorrect paths to start with.
This is the bare minimum needed to fetch data and if you get this to work you should see 10 random product names listed in your browser. Use the API doc and poke around in the client install files for more info and you should be up and running in no time.

Hope this helps.

Iceman
01-05-07, 16:33
Thank you very much Steve.

I couldn't find a book on SOAP & Webservices in the city centre bookshops anyway but it seems I don't need one.

This is going to be much easier than I thought.:)

authcode
01-05-07, 16:46
If you know your PHP you'll find the API pretty powerful, once you know where to start! Did that example code work for you? I hacked it together pretty quickly.

Iceman
01-05-07, 17:13
If you know your PHP you'll find the API pretty powerful, once you know where to start! Did that example code work for you? I hacked it together pretty quickly.

Yes it worked fine.

And I have just tried the searchProduct function and found it disappointing. For category camcorders (id 29), there are no Sony Camcorders it appears:

just accessories:

Sony SPKHCC Camcorder Marine Sports Pack
Sony P5-90MP3 video cassette
Sony DVM60PR3 Camcorder Tapes
Sony DVM60EXM2 Mini DV with IC Chip Digital Camcor
Sony DVM60PR
Li-Ion Camcorder Batteries ( SBLSM80 7.4V 800mAh )
SONY DVDRW RE-RECORDEABLE DISC (single)
Sony MSA64 Memory Stick
Sony MSHM64 Memory Stick
NiCd and NiMH Camcorder Batteries ( 6V 1800mAh Multi )
Sony ACCBDL
NiCd and NiMH Camcorder Batteries ( 3.6V 2500mAh Sharp )
Li-Ion Camcorder Batteries ( BNVM200U 7.4V 750mAh )
Sony LCSDVM Camcorder case Promotion
Sony NP-FM50 Digital Camcorder Battery
Sony ACCDVM Camcorder Kit
Sony DVM60PR3 (Pack of 5)
Sony LCSDVM Camcorder Case
Sony LCSCSF Black Soft carry case
NiCd and NiMH Camcorder Batteries ( 6V 1800mAh Canon )

But it does look pretty good. And fun. :D

authcode
01-05-07, 17:31
Yeah, the API's great, the data on the other hand... :rolleyes:

Iceman
01-05-07, 17:44
Yeah, the API's great, the data on the other hand... :rolleyes:

Yes, sadly you are right or I am doing things wrong. However, I seem to making a bit of progress by varyin the parameters.:)