Announcement

Collapse
No announcement yet.

API PHP POST Account and Conntact at same time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • API PHP POST Account and Conntact at same time

    Hi,
    I want to create an account and the contact at the same api call but my code doesn't work:

    try {
    $response = $client->request('POST', 'Account', [
    'name' => 'Testaccount',
    'accountnumber' => '12345',
    'emailAddress' => 'test@test.com',
    ]);

    $response = $client->request('POST', 'Contact', [
    'firstName' => 'Test firstName',
    'lastName' => 'Test lastName',
    'where' => [
    [
    'type' => 'equals',
    'attribute' => 'accountnumber',
    'value' => '12345',
    ],
    ],
    ]);

  • #2
    You need to pass the accountId created from the first POST request, to the second POST request, something like:

    $response_account = $client->request('POST', 'Account', [
    'name' => 'Testaccount',
    'emailAddress' => 'test@test.com',
    ]);

    $response_contact = $client->request('POST', 'Contact', [
    'firstName' => 'Test firstName',
    'lastName' => 'Test lastName',
    'accountId' => $response_account['id']
    ]);

    Comment

    Working...
    X