I need to add a note (activity) to a contact every time I take action on the contact in my application. As currently documented in the API docs, when you add a note it does not get attached to a contact. I need to be able to tell the API what contact I want the note attached too. I tried the modelRelations below, but this throws error
"You can add relations only for HAS_MANY and MANY_MANY relations"
$authenticationData = login(variable_get('zurmourl').'/zurmo/api/login',variable_get('zurmouser'),variable_get('zurmopass')) ;
if ($authenticationData) {
$headers = array(
'Accept: application/json',
'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'],
'ZURMO_TOKEN: ' . $authenticationData['token'],
'ZURMO_API_REQUEST_TYPE: REST',
);
$data = Array
(
'description' => 'Jim Save Note description',
'occurredOnDateTime' => date('Y-m-d H:i:s'),
);
$data['modelRelations'] = array(
'contacts' => array(
array(
'action' => 'add',
'modelId' => 31,
)
)
);
$response = createApiCall(variable_get('zurmourl').'/notes/note/api/create/' , 'POST', $headers, array('data' => $data));
$response = json_decode($response, true);
For this issue please check unit test: ApiRestNoteTest::testCreatewithRelations(). Here is code example:
$contact = ContactTestHelper::createContactByNameForOwner('Simon', $super);
$contactItemId = $contact->getClassId('Item');
$occurredOnStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
$data['description'] = "Note description";
$data['occurredOnDateTime'] = $occurredOnStamp;
$data['modelRelations'] = array(
'activityItems' => array(
array(
'action' => 'add',
'modelId' => $contact->id,
'modelClassName' => 'Contact'
),
),
);
$response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/notes/note/api/create/', 'POST', $headers, array('data' => $data));