API login session handling

Home Forums General Issues API login session handling

This topic contains 2 replies, has 2 voices, and was last updated by  AAC 1 year, 2 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2412

    AAC
    Participant

    Trying to get an idea on the best way to do this.

    PHP https://github.com/z2systems/neon-php:
    Using the NeonCRM API from a WordPress site, I am performing various tasks on user accounts mainly to do with data retrieval.

    These are the general steps per request:

    Login
    Run some method
    Logout

    Sometimes a series of requests are made at once in sequence which may appear like:

    Login
    Run some method
    Logout
    Login
    Run some method
    Logout
    Login
    Run some method
    Logout

    Issue is the login and logout is adding quite a bit of overhead in terms of time to complete the task.

    Obviously I can do this by storing the session and reusing, but is there a accepted method to handle this, and is there a session limit if new sessions are being created per site visitor
    Login
    Run some method
    Run some method
    Run some method
    .
    .
    .
    May or may not(Logout) or timeout on a cron

    #2413

    Colin Pizarek
    Keymaster

    The documentation for that PHP library states:

    “On the successful completion of this request, a Neon API session ID will be stored as a session variable. The library will automatically add this to subsequent requests.”

    The library store the Neon User Session ID as a session variable and references that session variable in subsequent requests. You can safely use this pattern as-is:

    Login
    Run some method
    Run some method
    Run some method

    …without storing the session yourself. The library already does that for you.

    The only thing you have to check for is expired sessions. The API will throw a “user session ID is invalid” error if you’re using an expired session. At that point, just log in again and continue.

    #2414

    AAC
    Participant

    Colin,

    Thanks for the quick reply. That sounds good, I will modify my code to follow that pattern.

    Thank you.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.