Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-15815

Two chained create calls, with the first one creating an array

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.5.5
    • Fix Version/s: Unscheduled
    • Component/s: CiviCRM API
    • Labels:
    • Documentation Required?:
      None
    • Funding Source:
      Contributed Code

      Description

      If you want to create a contact with two phone numbers and one website, and you do this like this:

      /dev1/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=create&json={"sequential":1,"contact_type":"Individual","first_name":"qwertyuiop","last_name":"asdfghjkl","api.Phone.create":[

      {"phone":"1207"}

      ,

      {"phone":"112"}

      ],"api.Website.create":{"url":"http://www.google.com"}}&api_key=yoursitekey&key=yourkey

      You get:

      { "fields":["contact_id"], "error_code":"mandatory_missing", "entity":"Contact", "action":"create", "is_error":1, "error_message":"Error in call to Website_create : Mandatory key(s) missing from params array: contact_id" }

      You seem to get this error when you use an array in a first chained call. If you switch the order of the chains, it does work:

      /dev1/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=create&json={"sequential":1,"contact_type":"Individual","first_name":"qwertyuiop","last_name":"asdfghjkl","api.Website.create":

      {"url":"http://www.google.com"}

      ,"api.Phone.create":[

      {"phone":"1207"}

      ,

      {"phone":"112"}

      ]}&api_key=yoursitekey&key=yourkey

      This workaround won't work if you want to add 2 websites and 2 phones at once.

      I tried to explicitly add "contact_id":"$value.id" to the second chained call:

      /dev1/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=create&json={"sequential":1,"contact_type":"Individual","first_name":"qwertyuiop","last_name":"asdfghjkl","api.Phone.create":[

      {"phone":"1207"}

      ,

      {"phone":"112"}

      ],"api.Website.create":{"url":"http://www.google.com","contact_id":"$value.id"}}&api_key=yoursitekey&key=yourkey

      I got:

      { "error_field":"contact_id", "type":"integer", "error_code":2001, "entity":"Contact", "action":"create", "is_error":1, "error_message":"Error in call to Website_create : contact_id is not a valid integer" }

      I know you will ask for a unit test But I am rather busy for the moment. I hope I will be able to provide one next week.

        Attachments

          Activity

            People

            • Assignee:
              eileen Eileen McNaughton
              Reporter:
              johanv Johan Vervloet
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: