Help get this topic noticed by sharing it on Twitter, Facebook, or email.
I’m frustrated

How can I select the "Product Collection" of an image with the API?

hi,

I have many photos (hundreds!) that need to be sold in a particular collections.

How can I select the "Product Collection" for a particular photo, with the API?

is there a way to indicate the collection by using a "class" attribute in the "img" tag for the photo being sold?

Or maybe better, fotomoto could add a call to a particular "set collection" function to associate a particular image to a particular collection. this could be done without changing the current API (i.e. 100% backward compatible).

With a function call to set a collection for a photo, this would not increase the fotomoto script load (the script load might be an issue if it had to check for a class in the DOM element for each photo).

i remember Ahmad mentioning that there would be a way of selecting the collection programmaticaly, for people using the API.

given the large number of images that i need to classify in various collections, i really cannot do that by hand for each photo with the fotomoto dashboard. so i desperately need a way to leverage this great feature with the API.
1 person has
this question
+1
Reply
  • Hi Tristan,

    Yes, you can do this now: please see http://support.fotomoto.com/customer/...

    The two functions are
    FOTOMOTO.API.checkinImage(image, callback, collection key)
    FOTOMOTO.API.FOTOMOTO.API.collectionList(callback)

    I hope that helps and kind regards,
    Derek
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • excellent, thanks! looks like that's what i need.

    i will try using those and will give you some feedback here.

    i have a few questions, though.

    what exactly is "collection key"? where do i get the collection key for my collections?

    what is "image"? is that the id if the image in the current DOM structure?

    could you give me a example of javascript that uses this call?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • there seems to be a typo in the page:
    http://support.fotomoto.com/customer/...

    FOTOMOTO.API.FOTOMOTO.API.collectionList(callback)
    should be:
    FOTOMOTO.API.collectionList(callback)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • also, i have a question regarding FOTOMOTO.API.checkinImage(image, callback, collection key)

    the documentation states:

    Overloaded function to allow the user to set the collection that the image is added to, you will need the collection key (use API.collectionList). If the Photo does not exist in our database, this should add the photo to our database into the said collection. It will also set all the analytics info. The callback function either returns the image object or null if it is unsuccesful and is asynchronous.

    but it does not say what it does if the image is ALREADY in the database. does it change the collection of the image (if it is in another collection)?

    in case it does not do that, how can i change the collection of an image that is already in the database?

    of course i could always delete ALL the images from the database, but that would not be very nice as it would cause unnecessary load on the fotomoto servers to rebuild the database... so i would prefer a way to change the collection of an image that is already in the database.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • well, i had to do a bit of reverse engineering because FOTOMOTO.API.checkinImage(image, callback, collection key) does not work for me....

    i am passing the id of the IMG element for image.
    i am passing a correct collection key '2e46da9f4aa5653d16a8f3f656f0328ec55bd147'

    and the image in question was not already in the database.

    here is a pretty-print of this API function:

    FOTOMOTO.API.checkinImage = function(d, g, e) {
    if (!FOTOMOTO.API.apiMode()) {
    alert("The widget is not in API Mode.");
    return
    }
    var a = function(j) {
    if (j != null) {
    var h = FOTOMOTO.getRelEntry(j, "ftmt_img");
    if (h != null) {
    j = new Image();
    j.src = h
    }
    }
    if (j != null) {
    FMJQ.getScript(FOTOMOTO.API.urls("photo_checkin", {img: encodeURIComponent(j.src),callback: c,store_key: e || FOTOMOTO_CONFIG.app_widget_id}))
    }
    };
    var c = FOTOMOTO.API.registerCallback(g);
    var b = FMJQ(d);
    if (b.length < 1) {
    b = FMJQ("#" + d)
    }
    if (b.length < 1) {
    var f = new Image();
    f.src = d;
    a(f)
    } else {
    b.each(function(h, j) {
    a(j)
    })
    }
    };

    everything works fine until it enters the loop in the "a" function, that calls

    the value of j is an HTMLImageElement (which is the correct one, that corresponds to the imageid that i passed), so this part of the code seems to work.

    i get to calling FMJQ.getScript but nothing happens there. the image is not added to the database, and my callback is never called.

    i'll try to do more reverse engineering and to understand why it does not work, but that does not seem to be normal.

    i might need to talk on the phone with the engineer in charge for that code.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • This reply was removed on 2011-11-19.
    see the change log
  • in my case, the URL returned by FMJQ.getScript is:

    http://widget.fotomoto.com/stores/pho...

    (copy this link to see the whole thing!)

    the URL of the image is correct. the "store_key" appears to be the key of the collection that i passed as a parameter.

    still not sure why it does not work.

    so i really need an engineer to look into the problem there.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • something else that i don't understand (probably an error in the documentation?)

    FOTOMOTO.API.checkinImage(image, callback, collection key)...The callback function either returns the image object or null if it is unsuccesful and is asynchronous.

    i think it should be:

    the callback will be called with one parameter. this parameter will be the image object or null if the image check-in was unsuccesful

    i don't thing FOTOMOTO.API.checkinImage cares about what the call-backs returns. correct?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • ohhh i think i have somehow screwed-up the database for the photo that i was using to test the API, and that may be what's causing my problems!

    the photo page for which the fotomoto database is screwedup is:
    http://www.loupiote.com/photos/221692...

    now fotomoto gives me this message when i just try to open the Print or Download dislog for this image:

    "Server Problem. Please try again later!"

    and the image is not found in the fotomoto database...

    i have no problems displaying the Print or Download dialog for my other images. just that one causes the problems, and if looks like it's because the checkin operation for it was partial / incomplete.

    could you look into that?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • all right, i was able to reproduce the issue with another photo.

    this time, i used http://www.loupiote.com/photos/221772...
    the URL for the image on that page is: http://www.loupiote.com/photos_m/2217...

    first, i removed this image from the fotomoto database (using the dashboard)

    then i called FOTOMOTO.API.checkinImage(image, callback, collection key)
    with
    image = the id for the img DOM element for the image on this page
    callback = my callback function
    collection key = 'ff7742205b8a7123b2069ca59c55619587665dd8'
    this is the collection key for my collection "No Download"

    what i observed:

    1) my callback was never called... this is not normal.... i tried other API calls FOTOMOTO.API.getImageProducts(image, callback), and with those my callback is called.

    2) i cannot find the image in the database using my dashboard (i looked in all the collections, and in the most recently accessed images)

    3) somehow the database now contains this image, but not associated with my collections. because i am now unable to open the PRINT dialog for this image (i get "Server Problem. Please try again later!").

    this is not good.... each time i FOTOMOTO.API.checkinImage, my image becomes unavailable... what's happening there?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Tristan's comment from other thread:

    to recap, here are my issues:

    1) the image checkin API does not seem to work

    2) because of 1), some of my images are now unavailable (but not in any of my collections), and i don't know how to correct that

    3) even if the checkin API was working, it is unclear if it could allow me to change the collection of an image akready in the database (in another collection)

    4) if the checkin API was not able to change the collection of an image (see 3), is there a workaround? is there a way to "un-checkin" or "remove" an image from the database with the API?

    5) if not, could you either change the checkin API so that it could change the image collection, or provide a way to delete the image so that it can be checked-in again in a different collection?

    thanks! :)

    -tristan
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited