OroCRM Forums

Covering OroCRM topics, including community updates and company announcements.

Forums Forums OroCRM OroCRM – Programming Questions REST API + Add Email to contact

This topic contains 10 replies, has 8 voices, and was last updated by Mike Kudelya Mike Kudelya 3 years, 9 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #24729

    diglin
    Participant

    Hi,

    I try to use the REST API to create new contacts. I manage to create new contacts if there are only basics content like FirstName, LastName, jobTitle, etc however I have an issue when I try to add an email:
    – The field ’email’ seems to be not allowed, I get error saying This form should not contain extra fields: \"email\"
    – Using the field ’emails’ has no effect. No email is created if I send the following json string {"contact":{"firstName":"Sylvain","lastName":"Ray\u00e9","source":"vcard","emails":{"email":"slyatremoveddiglin.com","primary":true}}}

    Well after some research, I see that the entity Contact is associated to ContactEmail for the property “emails”. In the API Controller, there is no call to the Contact entity method “addEmail” as it is done to appendAccount.

    Do you plan something about that or if I provide a fix, do you think I’m in the good direction by adding to the API Rest controller ContactController and in the ContactHandler a logic to add Emails?

    Thank you for your feedback.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Author
    Replies
  • #24730
    Dima Soroka
    Dima Soroka
    Keymaster

    We are going to add support of “email” field which will be saved as as primary email for a contact as well as support of /contacts/{id}/emails resource. Please fill free to contribute this improvements.

    #24731
    ignat
    ignat
    Participant

    Try to pass data in this format into your POST request:

    You should pass array of emails in contact.emails path. Try this:

    #24732

    diglin
    Participant

    Thank you to all for your feedbacks. I give a try and will notify you of the results :-)

    #24733

    diglin
    Participant

    Thanks @ignat your tip worked. I used json_encode in PHP and how I did, was not sufficient.
    I had to better prepare the data by doing such a thing:

    “`
    $data = array(
    ‘firstName’ => ‘Sylvain’,
    ‘lastName’ => ‘Rayé’,
    ‘source’ => ‘vcard’,
    ’emails’ => array(array(’email’ => ‘sylvainremovedatdiglin.com’, ‘primary’ => true)));
    “`

    It could help other people.

    #24734

    raul782
    Participant

    Hi guys,

    Is there something I’m missing when creating new contacts
    I’m testing with curl and proper wsse header, but the payload is not being bound with the contact entity

    The error I get when debugging is

    Pretty much tells me that I’m sending the wrong format.

    I’m using the version 1.1

    #24735

    raul782
    Participant

    Hi guys,

    Ignore my post, It works alright now, the debugging part was my mistake.
    Curl command could be useful for anybody testing their Api.

    Thanks

    #24736

    lassers
    Participant

    Hi guys

    Thanks for the information to create a contact via REST API.
    After that, is there anybody tried to create an account as well? How can we set the defaultContact or contacts when we POST to /api/rest/latest/account?
    The code below did not work:

    Is there any suggestion?

    Thanks

    #24737

    miken
    Participant

    In case someone else runs into this question and needs an answer. I found that the defaultContact needs to be an Id of an existing contact in the system and passed through as default_contact.

    #24738

    keberdle
    Participant

    Hi how to add email for contact by API
    WE try:

    With error:

    OroRestApi: curl return http 400 for url https://ORO.ltd/api/contacts – [{“title”:”extra fields constraint”,”detail”:”Tato skupina pol\\u00ed nesm\\u00ed obsahovat dal\\u0161\\u00ed pole.”,”source”:”emails.0″},{“title”:”extra fields constraint”,”detail”:”Tato skupina pol\\u00ed nesm\\u00ed obsahovat dal\\u0161\\u00ed pole.”,”source”:”phones.0″}]

    #24739
    Mike Kudelya
    Mike Kudelya
    Participant

    Hi

    Here i described how to work with new json api.

Viewing 10 replies - 1 through 10 (of 10 total)

The forum ‘OroCRM – Programming Questions’ is closed to new topics and replies.

You will be redirected to [title]. Would you like to continue?

Yes No