◦ Getting experience with the PHP programming language;
◦ Getting experience with the eBay Finding API;
◦ Getting hands-on experience in GCP App Engine, AWS or Azure.
1.1. Cloud exercise
The back-end of this homework must be implemented in the cloud on GCP, AWS or Azure using PHP.
See homework 5 for installation of either one of these platforms. You only have to select one platform to implement your back-end.
In this exercise, you are asked to create a webpage that allows you to search for products information using the eBay APIs, and the results will be displayed in a tabular format. The page will also provide product details, seller details and related products.
2.1. Description of the Search Form
A user first opens a page, called productSearch.php (or any valid web page name). You should use the ip-api.com HTTP API (See hint 3.3) to fetch the user’s geolocation, after which the search button should be enabled (it is initially greyed out and disabled when the page loads). The users must enter a keyword and choose what Category of the product they want to search (categories include Art, Baby, Books, Clothing, Shoes & Accessories, Computers/Tablets & Networking, Health & Beauty, Music and Video Games & Consoles) from a drop-down list. The default value for the “Category” drop-down list is “All Categories”, which covers all of the “types” provided by the eBay Finding API.
The users can also choose the Condition of the product they want based on new, used or unspecified. The default value for Condition is all for which none have to be checked. There is also a Shipping option for the users (Local Pickup and Free Shipping) which they choose as a filter. The default option is all for which neither of the options need to checked. Also, the users have option of enabling nearby search where they can enter the distance (in miles), which is the radius for the search where the center point is “Here” (zip code of current location returned from ip-api.com HTTP API) or the zip code entered in the edit box.
Only when the “Enable Nearby Search” is checked, the options to put the distance and select its center point should be enabled (it is initially greyed out and disabled when the page loads). When the “Here” radio button is selected, the zip code edit box must be disabled. When the zip code edit box is selected, it is a required field, and a 5-digit zip code must be entered. The default distance is 10 miles from the chosen location. Use HTML5 “placeholder” to show the string “zip
code” in the zip code edit box and “10” in the distance edit box as the initial values. An example is shown in Figure 1.
Figure 1(a): Initial Search Screen
Figure 1(b): Search Screen (after Enabling Nearby Search)
The Product Search form has two buttons:
Figure 2: An Example of a valid Search
Figure 3(a): An Example of Invalid Search (empty input)
Figure 3(b): An Example of Invalid Search (empty zip code)
Figure 3(c): An Example of Invalid Search (invalid zip code)
2.2 Displaying Products Results Table
In this section, we outline how to use the form inputs to construct HTTP requests to the eBay Finding API service and display the result in the web page.
The eBay Finding API service is documented here:
The eBay Finding API service to “make a call” is documented here:
The eBay Finding API service expects the following parameters:
• OPERATION-NAME: Set this field to be ‘findItemsAdvanced’.
• SERVICE-VERSION: Set this field to be ‘1.0.0’.
• SECURITY-APPNAME: Your application’s API key. This key identifies your application for purposes of quota management.
• RESPONSE-DATA-FORMAT: Set this field to ‘JSON’.
• REST-PAYLOAD: Add it to the API call.
• paginationInput.entriesPerPage: Set this to 20 to limit the number of results for a specific search.
• keywords: A term to be matched against all content that eBay has indexed for this place, including name of the product to be searched.
• categoryId: Filters the results to products matching the specified type id. Only one category may be specified (see Table 1). Searching without this field means searching in all categories.
Table 1: eBay Finding API – CategoryId Values for Various Categories
Clothing, Shoes & Accessories
Computers/Tablets & Networking
Health & Beauty
Video Games & Consoles
• There are 4 filters, namely Condition, Shipping Options, MaxDistance, HideDuplicateItems. Every filter should have two parameters (name and value). When listing the filters, they should be indexed starting from ZERO. An Example of listing two parameters:
If there are multiple values for a filter append it to the url using & operator:
• buyerPostalCode: Zip code of where the product needs to be searched. You can locate items that have been listed for nearby-markets only by specifying a buyerPostalCode and item filters and MaxDistance.
• MaxDistance: By default, it is set to 10. The user can set it to any number which specifies the radius from his location.
An example of an HTTP request to the eBay Finding API that searches for the products related to
USC within a 10 miles radius from the user’s current location is shown below:
Figure 5 shows an example of the corresponding JSON response returned by the eBay Finding API service response.
Figure 5: A sample JSON response returned by the eBay Finding API
Figure 6: An Example of a Valid Search result
Figure 7: An Example of an Empty Search result
When the search result contains at least one record, you need to map the data extracted from the API result to render the HTML result table as described in Table 2.
Table 2: Mapping the result from Graph API into HTML table
HTML Table Column
API service response
The value of the “index” is a number ranging
from 1 to 20 for all results.
The value of the “Photos” attribute is a part of
the “galleryURL” object inside the “item”
The value of the “Name” attribute is part of the
“title” object inside the “item” object.
The value of the “Price” attribute is part of the “currentPrice” object inside the “sellingStatus” object which is part of “item” object.
The value of the “Zip code” attribute is part of the “postalCode” object inside “item” object.
The value of the “Condition” attribute is part of the “condition” object inside “item” object. Set the value to “N/A” if it doesn’t exist.
The value of the “Shipping Option” attribute is part of the “shippingInfo” object inside “item” object. Set the value to “Free Shipping” if the “shippingServiceCost” is zero or set it to the value in dollars if it is not zero. Set it to “N/A” if no information is given.
2.3 Displaying Product Details (Product details and Seller Message and Similar Items)
In the search result table, if the user clicks on the name of a product, the page should make a request for the detailed information using the eBay shopping API documented at:
To retrieve the details of a single item, the request needs the following parameters (output should be JSON):
• callName: Set it to “GetSingleItem” to get information for a specific product.
• responseencoding: Set it to “JSON” to get a JSON response.
• appid: Your application’s API key. This key identifies your application for purposes of quota management.
• siteid: Set it to ‘0’ for siteId purposes.
• version: Set it to ‘967’ for API version purposes.
• ItemId: It is the “itemId” of the product the user clicked.
• IncludeSelector: Set it to “Description,Details,ItemSpecifics” to get required fields for that product.
An example of an HTTP request to the eBay Shopping API is shown below:
http://open.api.ebay.com/shopping?callname=GetSingleItem&responseencoding=JSO N&appid=[APPID]&siteid=0&version=967&ItemID=[ITEMID]&IncludeSelector=Descript ion,Details,ItemSpecifics
Figure 8 shows a sample corresponding response.
Figure 8: A sample JSON response from eBay Shopping API to get a Single Item.
Figure 9(a): An Example of a Valid Search result
Figure 9(b): An Example of a Valid Search result with missing fields
When the search result contains at least one field, you need to map the data extracted from the API result to render the HTML result table as described in Table 3.
Table 3: Mapping the result from eBay Shopping API into HTML Table
HTML Key API service response
Return Policy (US)
The value of the “ PictureURL” attribute that is part of the “Item” object.
The value of the “Title” attribute that is part of the “Item” object.
The value of the “ Subtitle” attribute that is part of the “Item” object.
The value of the “price” attribute that is part of the “currentPrice” object inside the “Item” object.
The value of the “Location” attribute that is part of the “Item” object along with its “postalcode” which is also a part of the “Item” object.
The value of the “UserId” attribute that is part of the “Seller” object inside the “Item” object.
The value of the “ ReturnPolicy” attribute that is part of the “Item” object.
The value of the all the “NameValueList” array
corresponding to that name inside the
“ItemSpecifics” object in the “Item” object.
Regarding the Seller Message on toggling Click to show seller message:
To retrieve the Seller Message, you should use the IFRAME tag to implement it. The height of that message is dynamic depending on the height of the inner html page embedded in it.
The information to be embedded in the IFRAME tag is the “Description” attribute which is present in the “Item” object.
An example of a Seller Message for an iPhone as a keyword is given below in Figure 11:
Figure 11: An Example of a Valid Seller Message
The details information includes two sub-sections: Seller Message and Similar Items which are by default hidden (i.e., collapsed) (as shown in Figure 12). The details information should over-write the result table and needs to be displayed under the search form. When the user clicks on
the button, the “seller message” sub-section should be expanded, and the “similar items” sub-section should be hidden (if it is open) and vice versa (see the video for the behavior).
Figure 12: Both the seller message and similar items are hidden
The “seller message” sub-section should display the seller message, as shown in Figure 13.
Figure 13: When seller message is clicked, similar items are hidden.
The “similar products photos” sub-section should display all photos (as shown in Figure 14) in a tabular format.
Figure 14: When similar items are clicked, seller message is hidden.
On clicking the button to show similar items, the page should request the detailed information using the eBay Merchandising API documented at:
To retrieve details of similar items, the request needs the following parameters (output should be
• OPERATION-NAME: Set it to “getSimilarItems” to get information for a related product.
• SERVICE-NAME: Set it to “MerchandisingService” to specify Merchandising API calls.
• SERVICE-VERSION: Set it to 1.1.0 for API version support.
• CONSUMER-ID: Your application’s API key. This key identifies your application for purposes of quota management.
• RESPONSE-DATA-FORMAT: Set it to ‘JSON’.
• REST-PAYLOAD: Add it to the API call.
• itemId: Set it to “itemid” of the product the user clicked.
• maxResults: Set it to 8 to limit the related products to 8 in a row.
An example of an HTTP request to the eBay Merchandise API that searches for similar products to the product clicked initially is shown below:
Figure 15 shows a sample corresponding response.
Figure 5: A sample JSON response returned by the eBay Merchandise API for getting similar items.
If the API service returns an empty result set, the page should display “No Seller Message Found” instead of the Seller Message section and should display “No Similar Items Found” instead of Similar Items section. Sample outputs are shown in Figure 16 and Figure 17.
Figure 16: When no Seller Message is found.
Figure 17: When no Similar Items are found.
2.4 Saving Previous Inputs
In addition to displaying the results, the web page should maintain the provided values. For example, if a user searches for “Keyword: USC, Category: Books, Condition: Used, Shipping Options: Free Shipping, Enable Nearby Search with 15 miles from Here”, the user should see what was provided in the search form when displaying the results. In addition, when clicking on a “Product”, the page should display the information about the product, seller message and similar products and keep the values provided in the search form. It follows that you need to keep the whole search box/input fields and buttons unmodified even while displaying results/errors.
In summary, the search mechanism to be implemented behaves as follows:
• Based on the query in the search form, construct a web service URL to retrieve the output from the eBay API service.
• Display the product information and seller message along with the similar items in the proper format.
3.1 How to get eBay API Key
• To get an eBay API key, please follow these steps given in the PDF file below: https://developer.ebay.com/DevZone/building-blocks/eBB_Join.pdf
3.2 Get geolocation using IP-API.com
You need to use ip-api.com for searching the geolocation based on IP addresses. An example call is as follows:
The response is a JSON object shown in Figure 22.
Figure 22: Response from ip-api.com API
This article introduces some similar APIs, so you have more choice for your homework 6:
https://ahmadawais.com/best-api-geolocating-an-ip-address/ Use of Freegeoip API is not recommended.
3.3 Parsing JSON-formatted data in PHP
In PHP 5 and 7, you can parse JSON-formatted data using the “json_decode” function. For more information, please go to http://php.net/manual/en/function.json-decode.php.
You can encode data into JSON-formatted objects using the “json_encode” function. For more information, please go to http://php.net/manual/en/function.json-encode.php.
3.4 Read and save contents in PHP
To read the contents of a JSON-formatted object, you can use the “file_get_contents” function.
To save contents on the server side, you can use “file_put_contents” function.
3.5 Deploy PHP file to the cloud (GAE/AWS/Azure)
You should use the domain name of the GAE/AWS/Azure service you created in HW #5 to make the request. For example, if your GAE/AWS/Azure server domain is called
example.appspot.co or example.elasticbeanstalk.com or example.azurewebsites.net, the following links will be generated:
GAE – http://example.appspot.com/productSearch.php
AWS – http://example.elasticbeanstalk.com/productSearch.php
Azure – http://example.azurewebsites.net/productSearch.php
example in the above URLs will be replaced by your choice of subdomain.
4. Files to Submit
In your course homework page, you should update the Homework 6 link to refer to your new initial web search page for this exercise (for example, productSearch.php). This PHP file must be hosted on GAE, AWS or Azure cloud service. Graders will verify that this link is indeed pointing to one of the cloud services.
Also, submit your source code file (it must be a single .php file, e.g. productSearch.php) to the GitHub Classroom repository so that it can be graded and compared to all other students’ source code via the MOSS code comparison tool.
• All discussions and explanations in Piazza related to this homework are part of the homework description and grading guidelines. So please review all Piazza threads, before finishing the assignment. If there is a conflict between Piazza and this description and/or the grading guidelines, Piazza always rules.
• You should not use JQuery for Homework 6.
• The link to the video is: https://youtu.be/ VtVYSgOwHbI