/    Sign up×
Community /Pin to ProfileBookmark

amazon API call with PHP

hey guys,

new here. For the last few weeks i’ve been focusing on trying to build a website that compiles prices for PC parts across various vendors. The trouble is, i’m somewhat of a PHP noob and don’t quite get how “all of the pieces fit together” yet.

the general idea is that a user submits a search query, and, if i’m understanding correctly, I store that query in a PHP variable to submit into the API call URL (along with whatever other parameters are required). Is this how the call is actually made? From here, the API call returns some XML dataset that I can use to dynamically generate by page HTML (depending on whatever product attributes I want to show).

Am I headed down the right path? Is there anyone who has done this who can offer some help or maybe a resource recommendation?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 23.2014 — The precise details may depend on the API specifics: e.g. if it's SOAP, you could use PHP's SOAPClient extension to interface with it. Otherwise you'll likely use the cURL extension to send/receive the requests and perhaps SimpleXML to parse/evaluate the responses. Chances are good that for Amazon's API there are already some reasonably robust PHP scripts/classes you could use, versus writing all the fiddly bits -- unless you want to use this as a good learning experience. ?
Copy linkTweet thisAlerts:
@ivanwakeupauthorOct 23.2014 — The precise details may depend on the API specifics: e.g. if it's SOAP, you could use PHP's SOAPClient extension to interface with it. Otherwise you'll likely use the cURL extension to send/receive the requests and perhaps SimpleXML to parse/evaluate the responses. Chances are good that for Amazon's API there are already some reasonably robust PHP scripts/classes you could use, versus writing all the fiddly bits -- unless you want to use this as a good learning experience. ?[/QUOTE]

I'm pretty sure amazon allows you to use either SOAP or REST, I don't understand the fine distinctions between the two but most examples i've reviewed seem to use REST.

I guess i'm just trying to understand the big picture and how all the pieces of writing this fit together.
Copy linkTweet thisAlerts:
@NogDogOct 23.2014 — The basic flow is:

1. Build the request data (xml, JSON, set of POST fields, or whatever that API requires)

2. Transmit that request via HTTP to the API's URI (e.g. via cURL)

3. Capture the response via HTTP (e.g. cURL)

4. Parse the response, again depending on what sort of data they return (XML, JSON, something else)

5. Base the rest of the application flow by what is in that response

If restful, that mainly just affects step 2, in that you have to tell cURL (or whatever HTTP interface you use) which HTTP method to use to send the request.

Hope that helped a tiny bit.
Copy linkTweet thisAlerts:
@ivanwakeupauthorOct 23.2014 — The basic flow is:

1. Build the request data (xml, JSON, set of POST fields, or whatever that API requires)

2. Transmit that request via HTTP to the API's URI (e.g. via cURL)

3. Capture the response via HTTP (e.g. cURL)

4. Parse the response, again depending on what sort of data they return (XML, JSON, something else)

5. Base the rest of the application flow by what is in that response

If restful, that mainly just affects step 2, in that you have to tell cURL (or whatever HTTP interface you use) which HTTP method to use to send the request.

Hope that helped a tiny bit.[/QUOTE]


Yes actually, this is extremely helpful. Gives me an idea of how i'm going to break down learning what I need to do into steps.
Copy linkTweet thisAlerts:
@GytisJul 13.2015 — hello ladies and gentlemen ! I have a question I want to import information into my website, I have ordered server, my website running with prestashop, no matter I can choose another CMS.

Can you tell me, how to do this step by step, 123... instruction.

API example, wich i want import into my website:

API

The project is a secret code Version Status

xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx 0.1 beta Active

0.1 beta

• API works REST API principle, all the data put into the form of JSON.

• Authorization

o Authorization wither and transfer your data provided during each referral. How it looks applying CURL support:

o curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

o curl_setopt($ch, CURLOPT_USERPWD, $api_project.':'.$api_secret);

o $api_project - Your project

o $api_secret - Your secret project code

• Data structure

o Error or not found data:

o {

o "error" : {

o "code" : 1,

o "message" : "Error"

o }

}

o Successfully obtain data:

o {

o "data" : {

o "id" : 12,

o "parentId" : 10,

o "name" : "Classic dresses"

o }

}

• [GET] /api/products[/{id}]

o {id} - specific product ID (not required)

o The product list

o {

o "data" : [

o {

o "id" : 1,

o "name" : "Dress (red)",

o "url" : "http://dropship.lt/-1",

o "category" : 1,

o "categories" : [2, 3],

o "code" : "abc123",

o "manufacturerId" : 1,

o "rrp" : 99.99,

o "price" : 50.00,

o "currency" : "EUR",

o "description" : "A short red dress",

o "text" : "A short red dress",

o "quantity" : 1,

o "variants" : [

o {

o "id" : 1,

o "quantity" : 9,

o "dispatch" : 1,

o "options" : [

o {

o "id" : 1,

o "type" : 1

o }

o ]

o },

o {

o "id" : 2,

o "quantity" : 9,

o "dispatch" : 1,

o "options" : [

o {

o "id" : 2,

o "type" : 2

o }

o ]

o },

o {

o ...

o }

o ],

o "images" : [

o "http://dropship.lt/img.jpg",

o "http://dropship.lt/img.jpg",

o ...

o ],

o "related" : [2, 3, 4]

o },

o {

o ...

o }

o ]

}

oThe options are:

§ category = {id [, id]} - Atfiltrated products under the category ID. You can transfer several categories ID, separated by commas. The delegation of parental category ID is returned in the deeper one category. /api/products?category=1 /api/products?category=1,2

• [GET] /api/quantities[/{id}]

o {id} - specific product ID (not required)

o The quantity of product summary

o {

o "data" : [

o {

o "id": 1,

o "quantity": 1,

o "dispatch": 1

o },

o {

o "id": 2,

o "variants": [

o {

o "id": 2,

o "quantity": 2,

o "dispatch": 2

o },

o {

o "id": 3,

o "quantity": 3,

o "dispatch": 3

o }

o ]

o },

o {

o ...

o }

o ]

}

o The options are:

§ Similar multi how /api/products

• [GET] /api/categories/{id}

o {id} - category ID:

o {

o "data" : {

o "id" : 12,

o "parentId" : 10,

o "name" : "Classic dresses"

o }

}

• [GET] /api/manufacturers/{id}

o {id} - manufacturer ID:

o {

o "data" : {

o "id" : 1,

o "name" : "Demo"

o }

}

• [GET] /api/attributes/{id}

o {id} - atribute ID:

o {

o "data" : {

o "id" : 1,

o "name" : "XXL",

o "type" : 1

o }

}

• [GET] /api/types/{id}

o {id} - attribute type ID:

o {

o "data" : {

o "id" : 1,

o "name" : "Dydis"

o }

}
×

Success!

Help @ivanwakeup spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...