Forums › Forums › OroCRM › OroCRM – Programming Questions › REST note create
This topic contains 6 replies, has 2 voices, and was last updated by Alan Culvi Bertomeu 6 years, 10 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- September 27, 2016 at 12:40 am #25293
When I want to add a note to a contact I get this error in the Log “Notes do not enabled or not updated for schema Given entity” contact “.”
But in the entity if enabled
This is the code that tried to create the note in the contact “$id”
PHP123456789if(isset($_POST['observaciones']) && $_POST['observaciones'] != ''){$url = "/api/rest/latest/notes";$verb = 'POST';$notaData['note[message]'] = $_POST['observaciones'];$notaData['note[entityId][id]']=$id;$notaData['note[entityId][entity]']='contact';$nota = $oro->goCurl($url,$verb,$notaData);print_r($nota);} - CreatorTopic
- AuthorReplies
- September 27, 2016 at 4:55 am #25294
Hi
Can you show me working example (code) ?
September 27, 2016 at 5:59 am #25295this is the class I use to connect to CRM
PHP123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132<?phpclass OroConnector{protected $_username;protected $_apiKey;protected $_userSalt;private $header;protected $_server = ' URL TO OROCRM ';public $debug;/*** @param $username* @param $apiUserKey* @param string $userSalt*/public function __construct ($debug = false, $apiUserKey=" API KEY ", $username=" USERNAME ", $userSalt = ''){$this->debug = $debug;$this->_username = $username;$this->_apiKey = $apiUserKey;$this->_userSalt = $userSalt; // deprecated in OroCRM v1.0}/*** @param $raw* @param $salt* @return string*/private function _encodePassword($raw, $salt){$salted = $this->_mergePasswordAndSalt($raw, $salt);$digest = hash('sha1', $salted, true);return base64_encode($digest);}/*** @param $password* @param $salt* @return string* @throws InvalidArgumentException*/private function _mergePasswordAndSalt($password, $salt){if (empty($salt)) {return $password;}if (false !== strrpos($salt, '{') || false !== strrpos($salt, '}')) {throw new \InvalidArgumentException('Cannot use { or } in salt.');}return $password.'{'.$salt.'}';}/*** @return array*/public function setHeader(){if(isset($_COOKIE['CRMID'])) unset($_COOKIE['CRMID']);$prefix = $this->_server;$created = date('c');$nonce = base64_encode(substr(md5(uniqid($prefix . '_', true)), 0, 16));$passwordDigest = $this->_encodePassword(base64_decode($nonce) . $created . $this->_apiKey, $this->_userSalt);$wsseProfile = sprintf('X-WSSE: UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"',$this->_username,$passwordDigest,$nonce,$created);$this->header = array('Authorization: WSSE profile="UsernameToken"',$wsseProfile);}public function getHeader(){return $this->header;}public function goCurl($url,$method,$data = array()){$ch = curl_init();if($method=='OPTIONS') $this->_header[] = 'OPTIONS';$this->setHeader();$curlOpt = array(CURLOPT_URL => $this->_server . $url,CURLOPT_RETURNTRANSFER => ($this->debug)?false:true,CURLOPT_HTTPHEADER => $this->header,CURLOPT_HEADER => ($this->debug)?true:false,CURLOPT_FAILONERROR => false,CURLOPT_NOBODY => false,CURLOPT_VERBOSE => ($this->debug)?true:false,CURLINFO_HEADER_OUT => ($this->debug)?true:false,);switch(strtoupper($method)){case 'POST':$curlOpt[CURLOPT_POST]=TRUE;BREAK;case 'PUT':$curlOpt[CURLOPT_CUSTOMREQUEST]='PUT';break;}if (!empty($data)) {$curlOpt[CURLOPT_POSTFIELDS] = $data;}curl_setopt_array($ch, $curlOpt);$result = curl_exec($ch);if ( $result === false) {$result = curl_getinfo($ch);}curl_close($ch);return $result;}}On the corporate website
PHP12345678910$id = (isset($isset[0]['id']))?$isset[0]['id']:$accountse->id;if(isset($_POST['observaciones']) && $_POST['observaciones'] != ''){$url = "/api/rest/latest/notes";$verb = 'POST';$notaData['note[message]'] = $_POST['observaciones'];$notaData['note[entityId][id]']=$id;$notaData['note[entityId][entity]']='contact';$nota = $oro->goCurl($url,$verb,$notaData);}September 29, 2016 at 5:31 am #25296Hi,
Please run api with
PHP1$notaData['note[entityId][entity]']='OroCRM\\Bundle\\ContactBundle\\Entity\\Contact';instead
PHP1$notaData['note[entityId][entity]']='contact';October 6, 2016 at 1:11 am #25297I added file vendor\oro\platform\src\Oro\Bundle\NoteBundle\Resources\config\oro\api.yml with this
It is possible to put this in a file in the app directory?
I’ve tried in app/Resources/config/oro/api.yml and create the app/Resources/config/gold/my_api.ymlYAML1234oro_api:entities:Oro\Bundle\NoteBundle\Entity\Note: ~Run the command
Shell1php app/console oro:api:cache:clearand then
Shell123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144php app/console oro:api:config:dump Oro\\Bundle\\NoteBundle\\Entity\\NoteOro\Bundle\NoteBundle\Entity\Note:identifier_field_names:- idexclusion_policy: allpost_serialize: \Closurefields:id: nullmessage: nullcreatedAt:data_transformer:- !php/object:O:64:"Oro\Bundle\ApiBundle\DataTransformer\DateTimeToStringTransformer":2:{s:16:"*inputTimezone";s:3:"UTC";s:17:"*outputTimezone";s:3:"UTC";}updatedAt:data_transformer:- !php/object:O:64:"Oro\Bundle\ApiBundle\DataTransformer\DateTimeToStringTransformer":2:{s:16:"*inputTimezone";s:3:"UTC";s:17:"*outputTimezone";s:3:"UTC";}owner:target_class: Oro\Bundle\UserBundle\Entity\Usercollapse: trueidentifier_field_names:- idexclusion_policy: allpost_serialize: \Closurefields:id: nullorganization:target_class: Oro\Bundle\OrganizationBundle\Entity\Organizationcollapse: trueidentifier_field_names:- idexclusion_policy: allpost_serialize: \Closurefields:id: nullupdatedBy:target_class: Oro\Bundle\UserBundle\Entity\Usercollapse: trueidentifier_field_names:- idexclusion_policy: allpost_serialize: \Closurefields:id: nullattachment:target_class: Oro\Bundle\AttachmentBundle\Entity\Filecollapse: trueexclude: trueidentifier_field_names:- idexclusion_policy: allpost_serialize: \Closurefields:id: nullcontact_6d50e87e:exclude: truetarget_class: OroCRM\Bundle\ContactBundle\Entity\Contactcollapse: trueidentifier_field_names:- idexclusion_policy: allpost_serialize: \Closurefields:id: nullaccount_a806e96b:exclude: truetarget_class: OroCRM\Bundle\AccountBundle\Entity\Accountcollapse: trueidentifier_field_names:- idexclusion_policy: allpost_serialize: \Closurefields:id: nulllead_5b29b7d2:exclude: truetarget_class: OroCRM\Bundle\SalesBundle\Entity\Leadcollapse: trueidentifier_field_names:- idexclusion_policy: allpost_serialize: \Closurefields:id: nullopportunity_ec95a95f:exclude: truetarget_class: OroCRM\Bundle\SalesBundle\Entity\Opportunitycollapse: trueidentifier_field_names:- idexclusion_policy: allpost_serialize: \Closurefields:id: nullorder_142bf5fc:exclude: truetarget_class: OroCRM\Bundle\MagentoBundle\Entity\Ordercollapse: trueidentifier_field_names:- idexclusion_policy: allpost_serialize: \Closurefields:id: nullcase_entity_217e0931:exclude: truetarget_class: OroCRM\Bundle\CaseBundle\Entity\CaseEntitycollapse: trueidentifier_field_names:- idexclusion_policy: allpost_serialize: \Closurefields:id: nulluser_b0b8032:exclude: truetarget_class: Oro\Bundle\UserBundle\Entity\Usercollapse: trueidentifier_field_names:- idexclusion_policy: allpost_serialize: \Closurefields:id: nullfilters:exclusion_policy: allfields:id:data_type: integerallow_array: trueowner:data_type: integerallow_array: trueorganization:data_type: integerallow_array: trueupdatedBy:data_type: integerallow_array: truesorters:exclusion_policy: allfields:id: nullowner: nullorganization: nullupdatedBy: nullbut when I try to collect all the notes
PHP1234567891011121314Array([errors] => Array([0] => Array([status] => 400[title] => entity type constraint[detail] => Unknown entity type: notes.)))October 6, 2016 at 4:23 am #25298My solution for this.
It is possible to put this in a file in the app directory?
I’ve tried in app/Resources/config/oro/api.yml and create the app/Resources/config/gold/my_api.yml1- I created a bundle
2- In created the file Resources/config/oro/api.yml in the bundle
3- In the file I wrote thisYAML1234oro_api:entities:Oro\Bundle\NoteBundle\Entity\Note: ~OroCRM\Bundle\ContactUsBundle\Entity\ContactRequest: ~May 18, 2017 at 5:14 am #25299On version 2.0 is simple
- AuthorReplies
The forum ‘OroCRM – Programming Questions’ is closed to new topics and replies.