REST API Specification – Opportunities

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

Get Opportunity

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

  • Description: Retrieve opportunity by id.
  • URL structure: http://crmme_url/index.php/opportunities/opportunity/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 opportunity id

$headers = array(
    'Accept: application/json',
    'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'],
    'ZURMO_TOKEN: ' . $authenticationData['token'],
    'ZURMO_API_REQUEST_TYPE: REST',
);
$response = ApiRestHelper::createApiCall('http://crmme_url/index.php/opportunities/opportunity/api/read/' . $id, 'GET', $headers);
// Decode json data
$response = json_decode($response, true);
if ($response['status'] == 'SUCCESS')
{
    $opportunity = $response['data'];
    //Do something with opportunity
}
else
{
    // Error, for example if we provided invalid opportunity id
    $errors = $response['errors'];
    // Do something with errors
}
  • Return:
    Data contains opportunity info.
{
  "status":"SUCCESS",
  "data":{
    "id":1,
    "createdDateTime":"2012-05-07 12:45:19",
    "modifiedDateTime":"2012-05-07 12:45:19",
    "createdByUser":{
      "id":1,
      "username":"super"
    },
    "modifiedByUser":{
      "id":1,
      "username":"super"
    },
    "owner":{
      "id":1,
      "username":"super"
    },
    "closeDate":"2011-01-01",
    "description":null,
    "name":"First Opportunity",
    "probability":0,
    "account":null,
    "amount":{
      "id":1,
      "value":500.54,
      "rateToBase":"1",
      "currency":{
        "id":1
      }
    },
    "stage":{
      "id":2,
      "value":"Negotiating"
    },
    "source":null
  },
  "message":null,
  "errors":null
}

Delete Opportunity

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

  • Description: Delete opportunity by id.
  • URL structure: http://crmme_url/index.php/opportunities/opportunity/api/delete/%id%
  • Method: DELETE
  • HTTP header parameters:
    Accept: application/json
    ZURMO_API_REQUEST_TYPE: REST
    ZURMO_SESSION_ID: %sessionId%
    ZURMO_TOKEN: %token%
  • Parameters: None
  • PHP sample:
$id = 1; // Change this value to opportunity id that you want to delete
$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://crmme_url/index.php/opportunities/opportunity/api/delete/' . $id, 'DELETE', $headers);
$response = json_decode($response, true);
if ($response['status'] == 'SUCCESS')
{
    // Inform user that opportunity is deleted
}
else
{
    // Error, for example if we provided invalid opportunity id
    $errors = $response['errors'];
    // Do something with errors
}
  • Return:
{
  "status":"SUCCESS",
  "data":null,
  "message":null,
  "errors":null
}

Create New Opportunity

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

  • Description: Create new opportunity
  • URL structure: http://crmme_url/index.php/opportunities/opportunity/api/create/
  • Method: POST
  • HTTP header parameters:
    Accept: application/json
    ZURMO_API_REQUEST_TYPE: REST
    ZURMO_SESSION_ID: %sessionId%
    ZURMO_TOKEN: %token%
  • Parameters:
$data = Array
(
    [name] => Michael
    [closeDate] => 2002-04-03
    [probability] => 10
    [description] => Opportunity description
    ['source'] => Array
        (
            [value] => Outbound
        )

    [account] => Array
        (
            [id] => 1
        )

    [amount] => Array
        (
            [value] => 100
            [currency] => Array
                (
                    [id] => 1
                )
        )

    [stage] => Array
        (
            [value] => Negotiating
        )
)
  • 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',
);
$data = Array
(
    'name' => 'Michael'
    'closeDate' => '2002-04-03'
    'probability' => 10
    'description' => 'Opportunity description'
    'source' => Array
        (
            'value' => 'Outbound'
        ),

    'account' => Array
        (
            'id' => 1
        ),

    'amount' => Array
        (
            'value' => 100,
            'currency' => Array
                (
                    'id' => 1,
                )

        ),

    'stage' => Array
        (
            'value' => 'Negotiating',
        )
);

$response = ApiRestHelper::createApiCall('http://crmme_url/index.php/opportunities/opportunity/api/create/', 'POST', $headers, array('data' => $data));
$response = json_decode($response, true);

if ($response['status'] == 'SUCCESS')
{
    $opportunity = $response['data'];
    //Do something with opportunity data
}
else
{
    // Error
    $errors = $response['errors'];
    // Do something with errors, show them to user
}
  • Return:
{
  "status":"SUCCESS",
  "data":{
    "id":2,
    "closeDate":"2002-04-03",
    "description":"Opportunity description",
    "name":"Michael",
    "probability":"10",
    "account":{"id":1},
    "amount":{
      "id":2,
      "value":"100",
      "rateToBase":"1",
      "currency":{
        "id":1
      }
    },
    "stage":{
      "id":3,
      "value":"Negotiating"
    },
    "source":{
      "id":4,
      "value":"Outbound"
    },
    "owner":{
      "id":1,
      "username":"super"
    },
    "createdDateTime":"2012-05-07 12:53:31",
    "modifiedDateTime":"2012-05-07 12:53:31",
    "createdByUser":{
      "id":1,
      "username":"super"
    },
    "modifiedByUser":{
      "id":1,
      "username":"super"
    }
  },
  "message":null,
  "errors":null
}

Update existing opportunity

Replace %id% with the id of the opportunity that you want to update, %sessionId% and %token% with ‘sessionId’ and ‘token’ variables returned by authentication process. Do note that if AutomaticProbabilityMapping is enabled in Opportunities module then user supplied probability values during update will be discarded.

  • Description: Update existing opportunity by id
  • URL structure: http://crmme_url/index.php/opportunities/opportunity/api/update/%id%
  • Method: PUT
  • HTTP header parameters:
    Accept: application/json
    ZURMO_API_REQUEST_TYPE: REST
    ZURMO_SESSION_ID: %sessionId%
    ZURMO_TOKEN: %token%
  • Parameters:
    All parameters are optional, so you can only provide properties that you want to update.
    For example:
$data = Array
(
    'probability' => "15";
)
  • PHP sample:
$id = 1; // Change this value to oportunity id that you want to change
$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',
);
// Change opportunity probability
$data['probability'] = "15";
$response = ApiRestHelper::createApiCall('http://crmme_url/index.php/opportunities/opportunity/api/update/' . $id, 'PUT', $headers, array('data' => $data));
$response = json_decode($response, true);
if ($response['status'] == 'SUCCESS')
{
    $opportunity = $response['data'];
    //Do something with opportunity data
}
else
{
    // Error, for example if we provided invalid oportunity id
    $errors = $response['errors'];
    // Do something with errors
}
  • Return:
    Code will return complete updated opportunity info.
{
  "status":"SUCCESS",
  "data":{
    "id":2,
    "closeDate":"2002-04-03",
    "description":"Opportunity description",
    "name":"Michael",
    "probability":"15",
    "account":{"id":1},
    "amount":{
      "id":2,
      "value":"100",
      "rateToBase":"1",
      "currency":{
        "id":1
      }
    },
    "stage":{
      "id":3,
      "value":"Negotiating"
    },
    "source":{
      "id":4,
      "value":"Outbound"
    },
    "owner":{
      "id":1,
      "username":"super"
    },
    "createdDateTime":"2012-05-07 12:53:31",
    "modifiedDateTime":"2012-05-07 12:53:31",
    "createdByUser":{
      "id":1,
      "username":"super"
    },
    "modifiedByUser":{
      "id":1,
      "username":"super"
    }
  },
  "message":null,
  "errors":null
}

Search opportunities

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

  • Description: Search opportunities
  • URL structure: http://crmme_url/index.php/opportunities/opportunity/api/list/filter/%searchFilter%
  • Method: GET, POST
  • HTTP header parameters:
    Accept: application/json
    ZURMO_API_REQUEST_TYPE: REST
    ZURMO_SESSION_ID: %sessionId%
    ZURMO_TOKEN: %token%
  • Query parameters:
$searchFilter = Array
(
    [pagination] => Array
        (
            [page] => 1
            [pageSize] => 3
        )
    [search] => Array
        (
            [name] => Sample
            [owner] => Array
                (
                    [id] => 1
                )
        )
    [sort] => name.desc
)
  • 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',
);
$searchParams = array(
    'pagination' => array(
        'page'     => 1,
        'pageSize' => 3,
    ),
    'search' => array(
        'owner' => array('id' => '1'),
    ),
    'sort' => 'name.desc',
);
// Get first page of results
$searchParamsQuery = http_build_query($searchParams);
$response = ApiRestTestHelper::createApiCall('http://crmme_url/index.php/opportunities/opportunity/api/list/filter/' . $searchParamsQuery, 'GET', $headers);
$response = json_decode($response, true);
if ($response['status'] == 'SUCCESS')
{
    // Do something with results
    if ($response['data']['totalCount'] > 0)
    {
        foreach ($response['data']['items'] as $item)
        {
        // Print opportunities
        }
    }
    else
    {
     // There are no opportunities
    }
}
else
{
    $errors = $response['errors'];
    // Do something with errors
}
// Now get second page (you might wanted to check if there are results on second page first)
$searchParams = array(
    'pagination' => array(
        'page'     => 2,
        'pageSize' => 3,
    ),
    'search' => array(
        'owner' => array('id' => '1'),
    ),
    'sort' => 'name.desc',
);

// Get second page of results
$searchParamsQuery = http_build_query($searchParams);
$response = ApiRestTestHelper::createApiCall('http://crmme_url/index.php/opportunities/opportunity/api/list/filter/' . $searchParamsQuery, 'GET', $headers);
$response = json_decode($response, true);
if ($response['status'] == 'SUCCESS')
{
    // Do something with results
    if ($response['data']['totalCount'] > 0)
    {
        foreach ($response['data']['items'] as $item)
        {
        // Print opportunities
        }
    }
    else
    {
     // There are no opportunities
    }
}
else
{
    $errors = $response['errors'];
    // Do something with errors
}
  • Return:
{
  "status":"SUCCESS",
  "data":{
    "totalCount":"5",
    "currentPage":2,
    "items":[
      {
        "id":4,
        "createdDateTime":"2012-05-07 13:13:50",
        "modifiedDateTime":"2012-05-07 13:13:50",
        "createdByUser":{
          "id":1,
          "username":"super"
        },
        "modifiedByUser":{
          "id":1,
          "username":"super"
        },
        "owner":{
          "id":1,
          "username":"super"
        },
        "closeDate":"2011-01-01",
        "description":null,
        "name":"Second Opportunity",
        "probability":0,
        "account":{
          "id":2
        },
        "amount":{
          "id":4,
          "value":500.54,
          "rateToBase":"1",
          "currency":{
            "id":1
           }
         },
         "stage":{
           "id":11,
           "value":"Negotiating"
         },
         "source":null
       },
       {
         "id":5,
         "createdDateTime":"2012-05-07 13:13:50",
         "modifiedDateTime":"2012-05-07 13:13:50",
         "createdByUser":{
           "id":1,
           "username":"super"
         },
         "modifiedByUser":{
           "id":1,
           "username":"super"
         },
         "owner":{
           "id":1,
           "username":"super"
         },
         "closeDate":"2011-01-01",
         "description":null,
         "name":"Third Opportunity",
         "probability":0,
         "account":{
           "id":2
         },
         "amount":{
           "id":5,
           "value":500.54,
           "rateToBase":"1",
           "currency":{
             "id":1
           }
         },
         "stage":{
           "id":12,
           "value":"Negotiating"
         },
         "source":null
       }
     ]
   },
  "message":null,
  "errors":null
}

Opportunities Dynamic Search

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

  • Description: Dynamic search opportunities
  • URL structure: http://crmme_url/index.php/opportunities/opportunity/api/list/filter
  • Method: GET, POST
  • HTTP header parameters:
    Accept: application/json
    ZURMO_API_REQUEST_TYPE: REST
    ZURMO_SESSION_ID: %sessionId%
    ZURMO_TOKEN: %token%
  • Query parameters:
$data = Array
(
    [dynamicSearch] => Array
        (
            [dynamicClauses] => Array
                (
                    [0] => Array
                        (
                            [attributeIndexOrDerivedType] => owner
                            [structurePosition] => 1
                            [owner] => Array
                                (
                                    [id] => 3
                                )

                        )

                    [1] => Array
                        (
                            [attributeIndexOrDerivedType] => name
                            [structurePosition] => 2
                            [name] => Fi
                        )

                    [2] => Array
                        (
                            [attributeIndexOrDerivedType] => name
                            [structurePosition] => 3
                            [name] => Se
                        )

                )

            [dynamicStructure] => 1 AND (2 OR 3)
        )

    [pagination] => Array
        (
            [page] => 1
            [pageSize] => 2
        )

    [sort] => name.asc
)
  • 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',
);
$data = array(
    'dynamicSearch' => array(
        'dynamicClauses' => array(
        array(
            'attributeIndexOrDerivedType' => 'owner',
            'structurePosition' => 1,
            'owner' => array(
                'id' => 3,
            ),
        ),
        array(
            'attributeIndexOrDerivedType' => 'name',
            'structurePosition' => 2,
            'name' => 'Fi',
        ),
        array(
            'attributeIndexOrDerivedType' => 'name',
            'structurePosition' => 3,
            'name' => 'Se',
        ),
        ),
        'dynamicStructure' => '1 AND (2 OR 3)',
    ),
    'pagination' => array(
        'page'     => 1,
        'pageSize' => 2,
    ),
    'sort' => 'name.asc',
);
// Get first page of results
$response = ApiRestTestHelper::createApiCall('http://crmme_url/index.php/opportunities/opportunity/api/list/filter/', 'POST', $headers, array('data' => $data));
$response = json_decode($response, true);
if ($response['status'] == 'SUCCESS')
{
    // Do something with results
    if ($response['data']['totalCount'] > 0)
    {
        foreach ($response['data']['items'] as $item)
        {
        // Print opportunities
        }
    }
    else
    {
     // There are no opportunities
    }
}
else
{
    $errors = $response['errors'];
    // Do something with errors
}
  • Return:
{
  "status":"SUCCESS",
  "data":{
    "totalCount":"5",
    "currentPage":2,
    "items":[
      {
        "id":4,
        "createdDateTime":"2012-05-07 13:13:50",
        "modifiedDateTime":"2012-05-07 13:13:50",
        "createdByUser":{
          "id":1,
          "username":"super"
        },
        "modifiedByUser":{
          "id":1,
          "username":"super"
        },
        "owner":{
          "id":1,
          "username":"super"
        },
        "closeDate":"2011-01-01",
        "description":null,
        "name":"Second Opportunity",
        "probability":0,
        "account":{
          "id":2
        },
        "amount":{
          "id":4,
          "value":500.54,
          "rateToBase":"1",
          "currency":{
            "id":1
           }
         },
         "stage":{
           "id":11,
           "value":"Negotiating"
         },
         "source":null
       },
       {
         "id":5,
         "createdDateTime":"2012-05-07 13:13:50",
         "modifiedDateTime":"2012-05-07 13:13:50",
         "createdByUser":{
           "id":1,
           "username":"super"
         },
         "modifiedByUser":{
           "id":1,
           "username":"super"
         },
         "owner":{
           "id":1,
           "username":"super"
         },
         "closeDate":"2011-01-01",
         "description":null,
         "name":"Third Opportunity",
         "probability":0,
         "account":{
           "id":2
         },
         "amount":{
           "id":5,
           "value":500.54,
           "rateToBase":"1",
           "currency":{
             "id":1
           }
         },
         "stage":{
           "id":12,
           "value":"Negotiating"
         },
         "source":null
       }
     ]
   },
  "message":null,
  "errors":null
}

Opportunities Improved Search

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

  • Description: Search opportunities – improved
  • URL structure: http://crmme_url/index.php/opportunities/opportunity/api/search/filter
  • Method: GET, POST
  • HTTP header parameters:
    Accept: application/json
    ZURMO_API_REQUEST_TYPE: REST
    ZURMO_SESSION_ID: %sessionId%
    ZURMO_TOKEN: %token%
  • Query parameters:
$data = Array
(
    [search] => Array
        (
            [modelClassName] => Opportunity
            [searchAttributeData] => Array
                (
                    [clauses] => Array
                        (
                            [1] => Array
                                (
                                    [attributeName] => owner
                                    [relatedAttributeName] => id
                                    [operatorType] => equals
                                    [value] => 1
                                )
                            [2] => Array
                                (
                                    [attributeName] => name
                                    [operatorType] => startsWith
                                    [value] => Fi
                                )
                            [3] => Array
                                (
                                    [attributeName] => name
                                    [operatorType] => startsWith
                                    [value] => Se
                                )
                        )
                    [structure] => 1 AND (2 OR 3)
                )
        )
    [pagination] => Array
        (
            [page] => 1
            [pageSize] => 2
        )
    [sort] => name asc
)
  • 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',
);
$data = array(
  'search' => array(
    'modelClassName' => 'Opportunity',
    'searchAttributeData' => array(
      'clauses' => array(
         1 => array(
           'attributeName'        => 'owner',
           'relatedAttributeName' => 'id',
           'operatorType'         => 'equals',
           'value'                => $userId,
         ),
         2 => array(
           'attributeName'        => 'name',
           'operatorType'         => 'startsWith',
           'value'                => 'Fi'
         ),
         3 => array(
           'attributeName'        => 'name',
           'operatorType'         => 'startsWith',
           'value'                => 'Se'
         ),
      ),
      'structure' => '1 AND (2 OR 3)',
    ),
  ),
  'pagination' => array(
    'page'     => 1,
    'pageSize' => 2,
  ),
  'sort' => 'name asc',
);
// Get first page of results
$response = ApiRestTestHelper::createApiCall('http://crmme_url/index.php/opportunities/opportunity/api/search/filter/', 'POST', $headers, array('data' => $data));
$response = json_decode($response, true);
if ($response['status'] == 'SUCCESS')
{
    // Do something with results
    if ($response['data']['totalCount'] > 0)
    {
        foreach ($response['data']['items'] as $item)
        {
        // Print opportunities
        }
    }
    else
    {
     // There are no opportunities
    }
}
else
{
    $errors = $response['errors'];
    // Do something with errors
}
  • Return:
{
  "status":"SUCCESS",
  "data":{
    "totalCount":"5",
    "currentPage":2,
    "items":[
      {
        "id":4,
        "createdDateTime":"2012-05-07 13:13:50",
        "modifiedDateTime":"2012-05-07 13:13:50",
        "createdByUser":{
          "id":1,
          "username":"super"
        },
        "modifiedByUser":{
          "id":1,
          "username":"super"
        },
        "owner":{
          "id":1,
          "username":"super"
        },
        "closeDate":"2011-01-01",
        "description":null,
        "name":"Second Opportunity",
        "probability":0,
        "account":{
          "id":2
        },
        "amount":{
          "id":4,
          "value":500.54,
          "rateToBase":"1",
          "currency":{
            "id":1
           }
         },
         "stage":{
           "id":11,
           "value":"Negotiating"
         },
         "source":null
       },
       {
         "id":5,
         "createdDateTime":"2012-05-07 13:13:50",
         "modifiedDateTime":"2012-05-07 13:13:50",
         "createdByUser":{
           "id":1,
           "username":"super"
         },
         "modifiedByUser":{
           "id":1,
           "username":"super"
         },
         "owner":{
           "id":1,
           "username":"super"
         },
         "closeDate":"2011-01-01",
         "description":null,
         "name":"Third Opportunity",
         "probability":0,
         "account":{
           "id":2
         },
         "amount":{
           "id":5,
           "value":500.54,
           "rateToBase":"1",
           "currency":{
             "id":1
           }
         },
         "stage":{
           "id":12,
           "value":"Negotiating"
         },
         "source":null
       }
     ]
   },
  "message":null,
  "errors":null
}

List Opportunity Attributes

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

  • Description: List all opportunity attributes.
  • URL structure: http://crmme_url/index.php/opportunities/opportunity/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://crmme_url/index.php/opportunities/opportunity/api/listAttributes', 'GET', $headers);
// Decode json data
$response = json_decode($response, true);
if ($response['status'] == 'SUCCESS')
{
    $opportunityAttributes = $response['data'];
    //Do something with opportunity attributes
}
else
{
    // Error
    $errors = $response['errors'];
    // Do something with errors
}
  • Return:
    Data contains opportunity attributes info.
Have more questions? Submit a request

Comments

Powered by Zendesk