PHP & XML Data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
haqker
Forum Newbie
Posts: 1
Joined: Sat Nov 13, 2010 11:52 pm

PHP & XML Data

Post by haqker »

Ive been hired to implement an API (XML data) into a a clients existing site. The client operates an online bookstore and recently partnered with campusbooks.com API documentation attached.

Ideally, I would like to incorporate the results from the API into the clients existing search engine(of his inventory only) I am stumped. :-/
Any help would be great.
Thank you
Your API Key: pTv36ERuuEuycz1qxHXF
CampusBooks.com API
Documentation (version 11)
The CampusBooks API allows permitted partner sites to utilize the power of the CampusBooks technology on
their own websites and applications. The API is implemented via an HTTP GET request in a standard REST
format. Results are returned in XML format.
This document specifies the protocol for submitting queries to the CampusBooks API and the results it will
return
Version 4 of the API builds upon version 3 by including additional pricing detail for book rentals. These offers
have a priced based on the number of days that the book is rented. The default price return in offer::price is for
the semester price. Other rental periods are contained in the offer::rental_detail array
Version 5 adds a searchid parameter to the bookprices, buybackprices, and prices requests. This may aid in
future functionality
Home :: API Key and Documentation
CampusBooks Partner Program http://partners.campusbooks.com/api.php
1 of 6 11/13/10 11:02 AM
Version 6 adds optional image_width and image_height parameters to the search, bookinfo, bookprices, and
buybackprices requests. The book image returned by the API will be of the size specified in either of these
parameters. If both parameters are given, only image_height will be used and image_width will be ignored. This
version also includes merchant logos for each offer in the prices, bookprices, and buybackprices requests.
Version 7 just makes some internal changes
Version 8 made some additional internal changes
Version 9 adds the abilty to return a response in JSON format
Version 10 adds coupon and home page link features
Version 11 updates filter for coupon and changes home page link format
Basic Query
http://api.campusbooks.com/11/rest/FUNC ... I_KEY_HERE[&<ADDITIONAL_ARGUMENTS>]
Each request to the CampusBooks API may contain the following parameters:
Key Description
Call The Name of the method that you want to call
Key This is the API Key assigned to you. It is unique to your site and is required for all calls
Additional
Arguments
Some calls accept (or require) additional parameters that can be passed as additional
parameters in the GET request
Responses
The root element of the XML returned will be a <response> element. The 'status' attibute indicates either 'ok' or
'error'.
On success, the <response> will include a <page> element with the results of your request. On failure, the
<response> element will contain an <errors> element containin a list of any errors that occurred
Successful Response
<response status="ok" version="11">
<page name="somepage">
<--...RESPONSE WOULD GO HERE ...-->
</page>
</response>
Error Response
<response status="error" version="11">
<errors>
<error>abcdefg is not a valid ISBN</error>
</errors">
</response>
CampusBooks Partner Program http://partners.campusbooks.com/api.php
2 of 6 11/13/10 11:02 AM
JSON Responses
You may append
&format=json
to any request and have the same data returned in a JSON format. The error response from immediately above
would lookl ike this:
{"response":{"@attributes":{"status":"error","version":"11"},"errors":{"error":"'abcdefg' is not a valid Constants
Book Conditions, Availaibities, and Merchant Names are all referenced by an ID in addition to their name. It is
recommended that your application use the ID field since it should be easier to parse, and it will remain
constant. The text fields may change slightly from time to time (ie: different formatting of a merchant name).
The 'constants' call returns the current ID/value pairs
Available Calls
Constants
The Constants call just returns a list of each of the types of constants, and their available id/value pairs
prices
The prices call requires a single valid ISBN to be passed in via a 'isbn' parameter:
http://api.campusbooks.com/11/rest/pric ... =ISBN_HERE
It returns groupings for each condition where each group contains multiple offers. Each offer contains the
following fields:
Key Description
isbn The thirteen digit ISBN for this offer
merchant_id A numeric merchant ID (Note, this value may be signed)
merchant_name The Name of the merchant (looked up from the defined constants)
merchant_image URL of the merchant logo
price The price that this merchant is listing this item for
shipping_ground The cost to ship to an address in the US via ground services
total_price Seller price plus the ground shipping price
link Link to purchase the book
condition_id Numeric representation of the condition (see constants)
condition_text Text representation of the condition
availability_id Numeric representation of the availability (how long it takes for the seller to ship it)
availability_text Text representation of the availability
CampusBooks Partner Program http://partners.campusbooks.com/api.php
3 of 6 11/13/10 11:02 AM
location Geographic location where this item ships from (not always present)
their_id The merchant's id for this offer (not always present)
comments Comments about this offering
condition_text Text representation of the condition
rental_detail
This node is available only for offers from book rental companies. If available, each sub-node
indicates a price for one of three rental periods (SEMESTER, TERM, or SUMMER)
days The exact number of days that this book may be rented for
price The price for this rental period
link
A link that will take the visitor to a page specific to this rental period (if supported by the
merchant)
bookinfo
The bookinfo call requires a single valid ISBN to be passed in via a 'isbn' parameter:
http://api.campusbooks.com/11/rest/book ... 0824828917[&image_height=HEIGHT][&It returns a 'page' element with all of the book attributes.
Key Description
isbn10 Ten-Digit ISBN for this book
isbn13 Thirteen-Digit ISBN for this book
title Book Title
author Book Author
binding Book Binding
msrp List price for the book
pages Number of pages in the book
publisher Book Publisher
published_date Published Date
edition Book Edition (ie: 2nd, 3rd, etc)
description A text description for the book
search
The search call can be used to do an author, title, or keyword search. It returns a list of books that match the
search criteria
http://api.campusbooks.com/11/rest/sear ... I_KEY_HERE&[&author=AUTHOR][&title=TITLE]
[&keywords=KEYWORDS][&page=1][&image_height=HEIGHT][&image_width=WIDTH]
At least one of 'author', 'title', or 'keywords' must be specified. The result contains up to 10 results on the page.
You can specify a page with the 'page' parameter'
Key Description
count The number of results for your search results (only 10 are displayed on this page)
CampusBooks Partner Program http://partners.campusbooks.com/api.php
4 of 6 11/13/10 11:02 AM
pages The number of pages of results available
current_page The current page you are on
results A list of books. The format of each is the same as from the bookinfo call defined above
bookprices
This function combines the bookinfo and prices functions into a single call. It requires an ISBN and returns the
book information as well as all of the pricing data
http://api.campusbooks.com/11/rest/book ... &isbn=ISBN[&image_height=HEIGHT][&image_Key Description
book
A book item. The contents of this item are the same as which is returned with the bookinfo
function
offers This node contains all of the pricing data that a call to the price function returns
buybackprices
This function combines the bookinfo request with buyback pricing information. It requires an ISBN and returns
buyback prices for all of the merchants that you have enabled.
http://api.campusbooks.com/11/rest/buyb ... &isbn=ISBN[&image_height=HEIGHT][&Key Description
book A book item. The contents of this item are the same as which is returned with the bookinfo function
offers This node contains an array of merchant nodes, each with the following structure
Key Description
merchant_id A numeric merchant ID
merchant_image URL of the merchant logo
name The name of the merchant
notes A text description about this merchant. It contains payment and shipping information about this merchant
prices prices contains a price node for each condition (new and used)
link The link for directing visitors to this merchant.
Sample
<merchant>
<merchant_id>108</merchant_id>
<merchant_image>http://www.campusbooks.com/images/marke ... name>First Class Books</name>
<notes>Free shipping via USPS or FedEx. Books must be ....</notes>
<prices>
<price condition="new">13.55</price>
<price condition="used">13.55</price>
</prices>
<link> http://partners.campusbooks.com/link.php?params=b3...
</merchant>
CampusBooks Partner Program http://partners.campusbooks.com/api.php
5 of 6 11/13/10 11:02 AM
merchants
This function returns a list of merchants and their home page links you can use for direct promotions. It can also
return a list of available coupons for that merchant. Use couponsonly to show only merchants with coupons.
http://api.campusbooks.com/11/rest/merc ... I_KEY_HERE[&coupons][&couponsonly][&type=[BUY|BUYBACK|Request Parameters
Key Description
type Optional. One of BUY, BUYBACK, or ALL. Defaults to ALL
coupons Optional. If present, coupons will included for each merchant
couponsonly
If present, ONLY merchants that have coupons will be included. Merchants without
coupons will be hidden
Response Fields
Key Description
name The name of the merchant
image A URL to the merchant image measuring less than 120x30 pixels
type The type of the merchant (BUY, BUYBACK)
merchant_id A numeric merchant ID
homepage_link A link for directing visitors to this merchants homepage if available
coupons This node contains the coupon information
coupons.coupon A container for each coupon
coupons.coupon.desc A text description of the coupon
coupons.coupon.exp Coupon Expiration Date in the format YYYY-MM-DD
Sample
<merchant>
<name>BookByte.com</name>
<type>BUY</type>
<image>http://www.campusbooks.com/images/marke ... jpg</image>
<merchant_id>27</merchant_id>
<homepage_link>
http://partners.campusbooks.com/link.ph ... 3tuP5ITFJl......
</homepage_link>
<coupons>
<coupon>
<desc>BookByte.com 5% Off Purchase of $40+ Use Code: save5</desc>
<expires>2010-12-31</expires>
</coupon>
<coupon>
<desc>BookByte 10% Off Orders of $20+ Use Code: Superdeal</desc>
<expires>2010-12-31</expires>
</coupon>
</coupons>
</merchant>
Post Reply