REST API Specification – Roles

Note: In all API calls, replace the % and example values between the % signs with your own variable values.

Get Role

Replace %id% with the id of the role that you want to retrieve, %sessionId% and %token% with ‘sessionId’ and ‘token’ variables returned by the authentication process.

  • Description: Retrieve role by id.
  • URL structure: http://zurmo_url/index.php/zurmo/role/api/read/%id%
  • Method: GET
  • HTTP header parameters:
    Accept: application/json
    ZURMO_API_REQUEST_TYPE: REST
    ZURMO_SESSION_ID: %sessionId%
    ZURMO_TOKEN: %token%
  • Parameters: None
  • PHP sample:
    $authenticationData = login('super','super');
    //Add code to check if user is logged successfully
    
    $id = 1; // Change this with value of role id
    
    $headers = array(
        'Accept: application/json',
        'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'],
        'ZURMO_TOKEN: ' . $authenticationData['token'],
        'ZURMO_API_REQUEST_TYPE: REST',
    );
    $response = ApiRestHelper::createApiCall('http://zurmo_url/index.php/zurmo/role/api/read/' . $id, 'GET', $headers);
    // Decode json data
    $response = json_decode($response, true);
    if ($response['status'] == 'SUCCESS')
    {
        $role = $response['data'];
        //Do something with role data
    }
    else
    {
        // Error, for example if we provided invalid role id
        $errors = $response['errors'];
        // Do something with errors
    }
    
  • Return:
    Data contains role info.

    {
      "status":"SUCCESS",
      "data":{
        "id":1,
        "createdDateTime":"2012-05-08 11:40:16",
        "modifiedDateTime":"2012-05-08 11:40:16",
        "createdByUser":{
          "id":1,
          "username":"super"
        },
        "modifiedByUser":{
          "id":1,
          "username":"super"
        },
        "name":"myRole"
      },
      "message":null,
      "errors":null
    }
    

Get All Roles

Replace %sessionId% and %token% with ‘sessionId’ and ‘token’ variables returned by the authentication process.

  • Description: Retrieve all roles.
  • URL structure: http://zurmo_url/index.php/zurmo/role/api/list/
  • Method: GET
  • HTTP header parameters:
    Accept: application/json
    ZURMO_API_REQUEST_TYPE: REST
    ZURMO_SESSION_ID: %sessionId%
    ZURMO_TOKEN: %token%
  • Parameters: None
  • PHP sample:
    $authenticationData = login('super','super');
    //Add code to check if user is logged successfully
    
    $headers = array(
        'Accept: application/json',
        'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'],
        'ZURMO_TOKEN: ' . $authenticationData['token'],
        'ZURMO_API_REQUEST_TYPE: REST',
    );
    $response = ApiRestHelper::createApiCall('http://zurmo_url/index.php/zurmo/role/api/list/', 'GET', $headers);
    // Decode json data
    $response = json_decode($response, true);
    if ($response['status'] == 'SUCCESS')
    {
        $roles = $response['data'];
        //Do something with roles
    }
    else
    {
        // Error
        $errors = $response['errors'];
        // Do something with errors
    }
    
  • Return:
    Data contains roles.

    {
      "status":"SUCCESS",
      "data":{
        "totalCount":"1",
        "currentPage":1,
        "items":[
          {
            "id":1,
            "createdDateTime":"2012-05-08 11:42:24",
            "modifiedDateTime":"2012-05-08 11:42:24",
            "createdByUser":{
              "id":1,
              "username":"super"
            },
            "modifiedByUser":{
              "id":1,
              "username":"super"
            },
            "name":"myRole"
          }
        ]
      },
      "message":null,
      "errors":null
    }
    

List Role Attributes

Replace %sessionId% and %token% with ‘sessionId’ and ‘token’ variables returned by authentication process.

  • Description: List contact attributes.
  • URL structure: http://zurmo_url/index.php/zurmo/role/api/listAttributes
  • Method: GET
  • HTTP header parameters:
    Accept: application/json
    ZURMO_API_REQUEST_TYPE: REST
    ZURMO_SESSION_ID: %sessionId%
    ZURMO_TOKEN: %token%
  • Parameters: None
  • PHP sample
    $authenticationData = login('super','super');
    //Add code to check if user is logged successfully
    
    $headers = array(
        'Accept: application/json',
        'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'],
        'ZURMO_TOKEN: ' . $authenticationData['token'],
        'ZURMO_API_REQUEST_TYPE: REST',
    );
    $response = ApiRestHelper::createApiCall('http://zurmo_url/index.php/zurmo/role/api/listAttributes', 'GET', $headers);
    // Decode json data
    $response = json_decode($response, true);
    if ($response['status'] == 'SUCCESS')
    {
        $roleAttributes = $response['data'];
        //Do something with role attributes
    }
    else
    {
        // Error
        $errors = $response['errors'];
        // Do something with errors
    }
    
  • Return:
    Data contains role attributes info.

Leave a Comment