SWHelp:StampWants API PHP Examples

From StampWantsWiki

Jump to: navigation, search

Here is some sample PHP (with cUrl) code you could use to make requests to the StampWants API:

//IMPORTANT - THE FOLLOWING FIELDS MUST BE SET
$username = "myUserName";
$password = "myPassWord";

//Example (username and password MUST be set above)
//$soldcsvString = stampwantsRequestSold();
//echo $soldcsvString;

//Another Example (username and password MUST be set above) temp.csv is a File Command CSV File on the server with this php Script
//$resultcsvString = stampwantsFileCommand("temp.csv");
//echo $resultcsvString;


function stampwantsRequestSold(){
	GLOBAL $username,$password;
	
	// We submit the request to stampwants
	
	$FileCommandURL = "http://www.stampwants.com/filecommand.php?username=".$username."&password=".$password."&type=sold&FCdateFrom=lastdownload";
	
	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_URL, $FileCommandURL );
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

	$result = curl_exec($ch);
	curl_close ($ch);
	
	//Should be a CSV file (as a string)
	return $result;
}

function stampwantsRequestUnSold(){
	GLOBAL $username,$password;
	
	// We submit the request to stampwants
	
	$FileCommandURL = "http://www.stampwants.com/filecommand.php?username=".$username."&password=".$password."&type=unsold&FCdateFrom=lastdownload";
	
	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_URL,$FileCommandURL);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTFIELDS); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

	$result = curl_exec($ch);
	curl_close ($ch);
	
	//Should be a CSV file (as a string)
	return $result;
}

function stampwantsFileCommand($commandfilename){
	GLOBAL $username,$password;
	
	$FileCommandURL = "http://www.stampwants.com/filecommand.php?username=".$username."&password=".$password."&type=upload";
	$postdata['auctionfile'] = "@".$commandfilename; //The @ in front makes CURL load the file content, not just use the literal string
	
	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_URL, $FileCommandURL );
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

	$result = curl_exec($ch);
	
	curl_close ($ch);
	
	//Should be a CSV file (as a string)
	return $result;
}
 
Personal tools
stampwants main site