REST API Specification – Authentication

Authentication

Before you can use any API functions, you need to authenticate a user.

  • Description: Authenticate user.
  • URL structure: http://zurmo_url/index.php/zurmo/api/login
  • Method: POST
  • HTTP header parametres:
    Accept: application/json
    ZURMO_API_REQUEST_TYPE: REST
    ZURMO_AUTH_USERNAME: %username%
    ZURMO_AUTH_PASSWORD: %password%
  • Parameters: None
  • PHP example:
    public function login($username, $password)
    {
        $headers = array(
            'Accept: application/json',
            'ZURMO_AUTH_USERNAME: ' . $username,
            'ZURMO_AUTH_PASSWORD: ' . $password,
            'ZURMO_API_REQUEST_TYPE: REST',
        );
        $response = ApiRestHelper::createApiCall('http://zurmo_url/index.php/zurmo/api/login', 'POST', $headers);
        $response = json_decode($response, true);
    
        if ($response['status'] == 'SUCCESS')
        {
            return $response['data'];
        }
        else
        {
            return false;
        }
    }
    
  • Return:
    Data contains array of sessionId and token elements.

    Response example:

    {
        "status":"SUCCESS",
        "data":{
            "sessionId":"9g4hl42qq55kuoblje038fmef4",
            "token":"f357a171e8cba6e8aad92a971922a5b3"
        },
       "message":null,
       "errors":null
    }
    

Leave a Comment

  • http://profiles.google.com/sibtiger33 Brian Stewart

    I’ve tried doing the above but I only get a response 302 redirect

    as anything changed in the API with the release to 1.0?

    • Ivica Nedeljkovic

      No we haven’t changed anything.
      But did you entered correct api url, instead ‘zurmo_url’ string? This login url usually look like(note ‘/app/’ in this url):
      http://www.example.com/app/index.php/zurmo/api/login

      If this doesn’t help, I suggest you to try to execute unit tests, to ensure that API is working fine.

      • http://profiles.google.com/sibtiger33 Brian Stewart

        Hi Ivica,

        I’ve checked again and when running the url I now get a 404 error (not found )

        /app/index.php/zurmo/api/login was not found on this server

        Really confused as the api did work fine last time.

        • Ivica Nedeljkovic

          Can you try to access url like this(replace zurmo.local with your zurmo url)
          http://zurmo.local/app/index.php/zurmo/api/login

          You should get an PHP error in this case, not 404 error.

          • http://profiles.google.com/sibtiger33 Brian Stewart

            Ok not to worry

            the problem was because zurmo is installed in a subdirectory called zurmo so if i changed the url to

            http://zurmourl/zurmo/app/index.php/zurmo/api/login

            all works !

          • http://profiles.google.com/sibtiger33 Brian Stewart

            Hi

            I’ve tried but I’m getting 404 errors

          • http://www.facebook.com/people/Ray-Stoeckicht/100001473956853 Ray Stoeckicht

            We have Developer Sessions every Tuesday at 10:00AM Chicago Time (http://zurmo.org/forums/index.php?/calendar/). You can always join an upcoming session and ask any questions to our technical team.