How can I get the parent ASIN of an item? - amazon-product-api

To get the variations of an item, we need to pass the ASIN of its parent item. But given a child item, is it possible to get the parent ASIN via the Amazon Product Advertising API?

Include VariationMatrix in your ResponseGroup. This is poorly documented in Amazon but it will give you the ASIN and ParentASIN for each Item. As far as I know it works in both ItemSearch and ItemLookup. Then do an ItemLookup using the ParentASIN and you will get Variations returned with an array of Items, all showing their ASIN, their variation dimensions, offers, etc.

If you haven't found your answer yet, the following request helped me get the parent ASIN.
$baba_item = array(
'Operation' => 'ItemLookup',
'ItemId' => 'B003O6CB6S',
'ResponseGroup' => 'Variations'
);
$baba_result = $amazon->queryAmazon($baba_item);
$parentASINi= $baba_result->Items->Item->ParentASIN;

Unfortunately, after a long search, I can say that it is not possible to get the parent ASIN via the current version (2011-08-02) of the Amazon Product Advertising API.
I hope in the future Amazon it will provide this functionality.

Related

How to get top X number of items according to a property in a paginated API?

Please note the question is purposely vague.
Assume, I have an API that returns paginated data of books. 100 book objects per page [This data is present in the headers like 'total-pages'. The response body is in the format of a list of JSON objects.
[
{},
{},
.
.
.
]
Assume book object has all the necessary data such as title, description, number of sales, etc, and so on. How do I return top-selling n number of books [top-selling => Highest number of sales]?
You cannot provide any parameters such as
GET endpoint/orderby=popularity&order=desc
to this endpoint and you cannot make any database query optimizations. How do we solve this problem with just pure code?
I'll be grateful for any ideas or suggestions.
Since the endpoint is limited in the parameters it accepts, your only option is to fetch all the pages (by continuously looping until it errors) and then sort it in your program it self.
If the above solution is slow, you can optimize by relaxing your requirements from return top-selling n number of books to return a few top-selling books which are in the top X%

How to assign correct answers to checkboxGridItem questions in a quiz?

One issue with using Google Forms to make a multiple choice quiz is that if a question has (for example) 3 points and 3 out of 5 correct answers, if a student only selects 2 of the 3 correct answers they will get 0 points, not 2.
The workaround for this is to use a checkboxGrid with only 1 column where each row is an answer choice.
Points can then be awarded for each correctly selected row.
I'm at a point where I want to create revision quizzes on the fly using this method, a snippet of my code that does this is here:
var question = questions[Math.floor(Math.random() * questions.length)];
var item = tasks.addCheckboxGridItem();
item.setTitle(question[1]);
item.setRows([ question[3],question[4],question[5],question[6],question,[7],question[8],question[9] ]);
item.setColumns(['Click if correct']);
I'm at a loss as to assign the correct answer and points to specific rows. I can see how to do this for a simple multiple choice question but not for this checkBoxgrid.
Issue:
GridItem and CheckboxGridItem currently don't support scoring. You cannot assign correct answers and points for these Items using Apps Script (e.g. createChoice(value, isCorrect), .setPoints(points)), nor retrieve this information (e.g. .isCorrectAnswer(), .getPoints(), .getScore()).
Feature Request:
There's currently a Feature Request related to this in Issue Tracker:
Allow user to get points and gat score of a GridItem
I'd suggest you to click the star on the top-left of the page in order to keep track of this and to help priorizing it.
Workaround:
In the meantime, your only options would be to use the UI instead, or to write a grading function yourself, as explained in the referenced issue:
- Find your Grid Item and grab it's ItemResponse.- Then get the response array.- Compare it to some grading function you create.- Return a score and use that number instead.
Of course, this workaround wouldn't add the scoring system to the Form itself, but it would be a way to handle quiz points programmatically.

Formatting a json returned by a RESTful API

If you were to call a restful api and were expecting to get a number (not one item) of items in json format. What would be the most correct format for an api to give this data to you:
a) [{"a":1, "b":2}, {"a":3,"b":4}] or
b) {"element1":{"a":1, "b":2}, "element2":{"a":3, "b":4}}
Or maybe there is a third way? Which one would be correct from the perspective of users working with this api?
If you were to call a restful api and were expecting to get a number (not one item) of items
Considering options A [{"a":1, "b":2}, {"a":3,"b":4}]
and B {"element1":{"a":1, "b":2}, "element2":{"a":3, "b":4}}
A is a list of items (note the [ ]). B is a single item (note the { }).
B just so happens to be an item that has multiple sub items, but it is still 1 single item.
Therefore your answer would be to go with A, as A is a list of items.
The 2 solutions are possible of course. But solution 1 is more light (not need to create a "element1", "elementN" for each item) and it's provide a more generic structure (for REST API especially).
And, also it's depends how you want manipulating the data. With array (solution 1), it's maybe more easy.

RESTful API for related objects

I am fairly new to REST and I have been struggling to map out RESTful requests for objects that are related by foreign keys in a mySQL database.
I have following objects and their relationships are in linear order:
Quiz_course [1]
Quiz_meta_block [2]
Quiz_block [3]
Quiz_question [4]
So far I have come up with the following GET requests:
// Retrieve all quiz_course(s)
api/quiz_course/
// Retrieve quiz_course by id
api/quiz_course/{id}
// Retrieve all quiz_meta_blocks related to a quiz_course id
api/quiz_course/{id}/quiz_meta_block
// Retrieve a quiz_meta_block that is related to a quiz_course_id
api/quiz_course/{id}/quiz_meta_block/{id}
But then I hit a wall when trying to get quiz_questions :
// Retrieve all quiz_questions that is related to a quiz_course_id
api/quiz_course/{id}/quiz_meta_block/quiz_block/quiz_question/
Is my representation accurate ?
I don't know what a block or meta block is in the context of a course, but I would go with something like the below. No need to prefix everything with quiz_*
../courses
../courses/n
../courses/n/meta-blocks
../courses/n/meta-blocks/n
../courses/n/meta-blocks/n/blocks
../courses/n/meta-blocks/n/blocks/n
../courses/n/meta-blocks/n/blocks/n/questions
../courses/n/meta-blocks/n/blocks/n/questions/n
You could also give direct access to, say, all questions in a course like this:
../courses/n/questions

Is there an API that retrieves a list of items for a given category?

I figure since Google Sets used to exist and somewhat still does, there must exist some API (google or otherwise) where I could send a category as a GET request and retrieve a JSON listing of items in that category.
For example:
In: 'sports'
Out: {'basketball', 'football', 'baseball', 'hockey', 'soccer', 'lacrosse', ...}
In: 'animals'
Out: {'dog', 'cat', 'fish', 'bird', 'horse', ...}
I'm thinking that the answer might have something to do with Google's custom search API, or perhaps even Wikipedia?
Thanks!
Your best bet is probably an MQL query to freebase
http://wiki.freebase.com/wiki/MQL
Something like this for sports