Skip to content

Instantly share code, notes, and snippets.

@scoop
Created April 6, 2013 07:59
Show Gist options
  • Save scoop/5325344 to your computer and use it in GitHub Desktop.
Save scoop/5325344 to your computer and use it in GitHub Desktop.
Modified example Gist for Alfred 2 to use Amazon Suggest for Amazon.de (instead of the default Amazon.com). Note: Remove `<?php .. ?>`, which I only added for syntax highlighting purposes.
<?php
require('workflows.php');
$w = new Workflows();
// Grab input and build query url string
$in = "{query}";
$url = "http://completion.amazon.co.uk/search/complete?method=completion&q=".urlencode( $in )."&search-alias=aps&mkt=4&x=updateISSCompletion&noCacheIE=1295031912518";
// Grab the data from Amazon
$str = $w->request( $url );
// Strip off the "header" data
$str = substr( $str, strlen( 'completion = ["'.$in.'",[' ) );
// Remove the node info
$str = substr( $str, 0, strpos( $str, ']' ) );
// Check to see if results were found
if ( $str == "" ):
$w->result( time(), $in, 'No Suggestions', 'No search suggestions found. Search Amazon for '.$in, 'icon.png', 'yes' );
else:
// Remove the double quotes around all the strings,
$str = str_replace( '"', '', $str );
// Split into an array using a comma as the delimiter
$options = explode( ',', $str );
// Loop through each result and make a feedback item
foreach( $options as $option ):
$w->result( time(), $option, $option, 'Find '.$option.' on Amazon', 'icon.png', 'yes', $option );
endforeach;
endif;
// Return the result xml
echo $w->toxml();
?>
@scoop
Copy link
Author

scoop commented Apr 6, 2013

Main difference from stock PHP code:

  • Changed to use completion.amazon.co.uk instead of completion.amazon.com
  • Changed from mkt=1 to mkt=4 in the query string

@JasperYanky
Copy link

Any more document about completion search ? I'd like to know how to search Italia&UK's data.Thanks!

@grzeczko
Copy link

@scoop What does changing from mkt=1 to mkt=4 do?

@wrtsprt
Copy link

wrtsprt commented Sep 22, 2017

I still had to change the result action in the Alfred workflow from 'Default Web Search' to 'OpenURL' using the search URL of the German store (otherwise it will open a suggestion in the .com store).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment