You are here: Home / Documentation / 6. Add-ins / 6.6 eWay-CRM API / Get, Save and Search Items

Get, Save and Search Items

Methods description and their usage

Modules that are available via eWay-CRM API has methods that can be called. Basic methods are (instead of XXX there is module name in the method):

  • SaveXXX - you can save an item
  • SearchXXX - you can search in items
  • GetXXX - you can get some items

Methods are similar for all modules and you can get their list when you activate documentation right on your web service. Methods will be presented on Contacts module. They can be applied in similar way for other modules.

SaveContact Method

SaveContact method is used within creation of new contact in eWay-CRM. Method calling and its parameters are described below. There are also described the return values. All available parameters can be found after activation of documentation on your web service.

First we have to define item (contact in our case) that we want to create - we declare a variable in which we will define array with new contact parameters.

$contact = array(
    'FirstName' => 'Robert',
    'LastName' => 'Doe',
    'Email1Address' => '[email protected]',
    'TelephoneNumber1' => '586987456',
    'BusinessAddressStreet' => 'Atlantic Ave',
    'AdditionalFields' => array ( 'af_18' => 'Snowboarding',
    'af_146' => '8.11.2005')
);

Consequently we will use $connector variable for calling the SaveContact method and as a parameter we will pass our variable $contact.

$result = $connector->SaveContact($contact);

Afterwards we will create simple condition for result verification. In case of successful result we will print identification number of new contact. Otherwise we will print notification with further information about problem.

if ($result->ReturnCode == 'rcSuccess')
{
    print ("New contact created with Guid " . $result->Guid);
}
else{
    print("Unable to create new contact:" . $result->Description);
}

Result will look like below.

To edit the contact later you have to specify item identificator ItemGUID and version of item (ItemVersion), which has to be increased with each other call by one.

$contact = array(
    'ItemGUID' => 'b604815a-8cce-4600-ae22-8bc38e4c8f66'
    'ItemVersion' => '2',
    'TelephoneNumber1' => '+420586987456'
);

More examples of how to save items are available on GitHub.

SearchContacts Method

SearchContacts method is used for searching for a specific contact in eWay-CRM. Below is described example of its calling within PHP script and its return values. All available parameters can be found after activation of documentation on your web service.

First we have to define item (contact in our case), which we want to find - we declare a variable, in which we will define array with parameters of searched contact.

$contact = array(
    'FirstName' => 'Robert',
    'LastName' => 'Doe',
    'Email1Address' => '[email protected]',
);

Consequently we will call SearchContacts method on $connector variable and we will use our defined $contact as a parameter.

$result = $connector->SearchContacts($contact);

For formatted output we will print search result with following code.

if ($result->ReturnCode == 'rcSuccess')
{
    print("<pre>");
    print_r($result->Data);
    print("</pre>");
}
else
{
    print("Unable to get contact:" . $result->Description);
}

And again we will print error message in case of failure. Result will look, for example, as below:

We can also want just specific information, so for this purpose we just simply specify our output, for example, as below.

print($result->Data[0]->BusinessAddressStreet); 

And we will get just one information:

GetContacts Method

GetContacts method is used for complete list of all contacts in eWay-CRM. Below is described its calling within PHP script and its return values. This time we don't have to specify any parameter for GetContacts method and we can just call it. We will use our $connector variable and call the GetContact method without parameters.

$result = $connector->GetContacts();

For formatted output we will print result with following code.

if ($result->ReturnCode == 'rcSuccess')
{
    print("<pre>");
    print_r($result->Data);
    print("</pre>");
}
else
{
    print("Unable to get contacts: " . $result->Description);
}

Result is list of all contacts, which will look as below (it is just part of whole result - all contacts).

Output can be also formatted arbitrarily.