how to get case deatails from contacts using api method?

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
# @km
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class getContacts extends SugarApi
{
public function registerApiRest()
{
return array(
//GET
'getContacts' => array(
//request type
'reqType' => 'POST',
//endpoint path
'path' => array('CONTACTS', 'getContacts'),
//endpoint variables
'pathVars' => array('', ''),
//method to call
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Parents
  • and what is exactly your question? The code you posted will return the first case related to the specified contact, if the contact can be found and if there are any cases related to that specific contact and if the json you create is valid according to json_encode..

  • i want to get case details from specific contacts.

  • I think your code should return what you are after - it looks like it will provide the list rather than just the first one to me. However, your 'path' is not correct as you have the module in full upper case: 'CONTACTS'. This should be just in title case, 'Contacts' so the line needs to read:

    Fullscreen
    1
    2
    //endpoint path
    'path' => array('Contacts', 'getContacts'),
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    That is the first thing I would fix if debugging this code sample.

    Thanks,

    JH.

Reply
  • I think your code should return what you are after - it looks like it will provide the list rather than just the first one to me. However, your 'path' is not correct as you have the module in full upper case: 'CONTACTS'. This should be just in title case, 'Contacts' so the line needs to read:

    Fullscreen
    1
    2
    //endpoint path
    'path' => array('Contacts', 'getContacts'),
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    That is the first thing I would fix if debugging this code sample.

    Thanks,

    JH.

Children
  • Also, in your $return_data array you are not correctly referencing the Contact details. You have put:

    Fullscreen
    1
    $return_data = array('contact_id' => $contactDetails[0]['id'],'First Name:' => $contactDetails[0]['first_name'],'Last Name:' => $contactDetails[0]['last_name'],'Cases' => $responsearry);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    although you do not have any object called $contactDetails (I guess this is from previous adjustments when debugging). This needs to be:

    Fullscreen
    1
    $return_data = array('contact_id' => $Contact->id,'First Name:' => $Contact->first_name,'Last Name:' => $Contact->last_name,'Cases' => $responsearry);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Thanks,

    JH.