new to this: POST JSON data for method requests? How to check if a sess_ID is valid?

pjvendapjvenda Registered Users Posts: 2 Beginner grinner
Hi everyone,

First post and, yes, it's a question. Not starting well, I'm afraid :-/ On to it:

I've started writing some PHP to interact with smugmug's API. First issue I've found was: I was not able to POST JSON serlialised data to the JSON API. Intuitively I considered that the JSON API would take JSON formatted queries (via POST) and respond JSON. Am I wrong?
As a workaround, I'm doing GET requests (REST style) and parsing JSON responses, which works fine. Is this the intended method?

Is there a way to check if a session identifier is valid or is still valid? I'm assuming I can send it via GET parameter SessionID=<id> or in a cookie. But is there a sample request I can make that succeeds if the session is valid and fails if it is not?
In terms of PHP code, I would not like to request a session identifier every time I call a particular method. If my library is called in several pages of an application, I'm guessing I need to keep the session identifier somewhere non-volatile to be able to re-use it. But until when?

Thanks in advance for any help that comes this way.
Cheers,
Pedro.

Comments

  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited September 23, 2010
    G'day Pedro,

    yes, you are correct in your observation that we don't currently support posting a native JSON structure. it's something that I want to do, but at this stage, it's more of a nice to have over some other API functionality that is missing.

    Our API sessions stay active for 24 hours with no activity, so you could keep track of each time an API method is called from your app, and then the next time you need to call a method, determine if you need to renew your session or not.

    Also, if you are using php, there is an existing php wrapper/library that you might find useful.

    Cheers,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • pjvendapjvenda Registered Users Posts: 2 Beginner grinner
    edited September 24, 2010
    Hi David,

    Many thanks for your invaluable response.

    I will knock something up with regards to session timeouts, etc. Is the 24h period the same for anonymous and password logins? I am also assuming that the session is instantly killed if the 'logout' method is called (this is more security than functionality...)?

    As for the mentioned wrapper... well... let's just say I enjoy reinventing the wheel sometimes :]

    Cheers,
    Pedro.
Sign In or Register to comment.