diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 59a8a53ffd7..74316bc1e0f 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -1146,6 +1146,42 @@ class Thirdparties extends DolibarrApi return $returnNotifications; } + /** + * Create CompanyNotification object for thirdparty + * @param int $id ID of thirdparty + * @param array $request_data Request data + * + * @return array|mixed Notification of thirdparty + * + * @url POST {id}/notifications + */ + public function createCompanyNotification($id, $request_data = null) + { + if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) { + throw new RestException(403, "User has no right to update thirdparties"); + } + if ($this->company->fetch($id) <= 0) { + throw new RestException(404, 'Error creating Thirdparty Notification, Thirdparty doesn\'t exists'); + } + $notification = new Notify($this->db); + + $notification->socid = $id; + + foreach ($request_data as $field => $value) { + $notification->$field = $value; + } + + if ($notification->create(DolibarrApiAccess::$user) < 0) { + throw new RestException(500, 'Error creating Thirdparty Notification'); + } + + if ($notification->update(DolibarrApiAccess::$user) < 0) { + throw new RestException(500, 'Error updating values'); + } + + return $this->_cleanObjectDatas($notification); + } + /** * Delete a CompanyNotification attached to a thirdparty *