Jump to content


Photo

api create methods related to the marketingLists models

marketingLists api marketingLists api

  • Please log in to reply
No replies to this topic

#1 Bouguedima

Bouguedima

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 22 January 2015 - 04:12 PM

any help on how create new API method related to the marketingLists.?

 

i have follow this tutorial but i think that i have an error

 

http://zurmo.org/wik...-custom-models 

 

here is my codes

 

<?php
 
//class MarketingListApiController extends ZurmoModuleApiController {
 
class MarketingListApiController extends ZurmoModuleApiController {
 
 public function actionCustomGet() {
  $params = Yii::app()->apiHelper->getRequestParams();
  if (!isset($params['id'])) {
   $message = Yii::t('Default', 'The id specified was invalid.');
   throw new ApiException($message);
  }
  $result = $this->processRead((int) $params['id']);
  Yii::app()->apiHelper->sendResponse($result);
 }
 
 public function actionCustomList() {
  $params = Yii::app()->apiHelper->getRequestParams();
  $result = $this->processList($params);
  Yii::app()->apiHelper->sendResponse($result);
 }
 
 public function actionCustomPost() {
  
 
  $params = Yii::app()->apiHelper->getRequestParams();
  if (!isset($params['data'])) {
   $message = Yii::t('Default', 'Please provide data.');
   throw new ApiException($message);
  }
  $result = $this->processCreate($params['data']);
  Yii::app()->apiHelper->sendResponse($result);
 }
 
 public function actionCustomUpdate() {
  $params = Yii::app()->apiHelper->getRequestParams();
  if (!isset($params['id'])) {
   $message = Yii::t('Default', 'The id specified was invalid.');
   throw new ApiException($message);
  }
  $result = $this->processUpdate((int) $params['id'], $params['data']);
  Yii::app()->apiHelper->sendResponse($result);
 }
 
 public function actionCustomDelete() {
  $params = Yii::app()->apiHelper->getRequestParams();
  if (!isset($params['id'])) {
   $message = Yii::t('Default', 'The id specified was invalid.');
   throw new ApiException($message);
  }
  $result = $this->processDelete((int) $params['id']);
  Yii::app()->apiHelper->sendResponse($result);
 }
 
 protected function getModelName() {
  return 'MarketingList';
 }
 
 protected function getSearchFormClassName() {
  return 'MarketingListsSearchForm';
 }
 
}
?>
 
and add this code the perInstance.php
 
 
   $instanceConfig['components']['urlManager']['rules'] = array(
 
    array('marketingLists/<model>Api/<action>', 'pattern' => 'marketingLists/<model:\w+>/api/<action>/*'),
 
)
 
and here is method call
 
 
 $authenticationData = login_api();
 $headers = array(
    'Accept: application/json',
    'ZURMO_SESSION_ID: ' . $authenticationData['data']['sessionId'],
    'ZURMO_TOKEN: ' . $authenticationData['data']['token'],
    'ZURMO_API_REQUEST_TYPE: REST',
);
 
 
// Add below elements depending on custom model
$data = Array
(
    'name' => 'List name',
);
 
$response = createApiCall2('http://127.0.0.1/zur...api/customPost/' 'POST', $headers, array('data' => $data));
 
 
 
any help please ??
regards
Omar






Also tagged with one or more of these keywords: marketingLists api, marketingLists, api

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users