Add-Contact
  • 5 Minutes to read
  • Dark
    Light
  • PDF

Add-Contact

  • Dark
    Light
  • PDF

Article summary

Summary

Creates a new contact.

Add-Contact
    -Entry
    -BypassCustomFieldValidation

Returns a contact object.

Parameters

Parameter

Type

Required?

Notes

Entry

Contact Object

Yes


BypassCustomFieldValdiation

Switch

No, Defaults to false

Ignores required field requirement for custom fields when the entry is saved.

Examples

Create a new contact (no custom fields)

# Create a new contact (no custom fields)

# Create an object with the necessary fields to create the contact
# Note: The email field is the only required system field for the contact object

$entry = @{
    EmailAddress        = "econnor@company.com"
    FirstName           = "Ellena"
    LastName            = "Connor"
    TimeZoneIdentifier  = "Central Standard Time"
}

# Create the contact. The created entry will be returned back.
$data = Add-Contact -Entry $entry

# Output some information to help indicate that the contact was created
Write-Output "Contact $($data.ContactId) ($($data.NameAndEmailAddress)) was created"

# For debug purposes, convert the data to output as JSON so we can see all the fields
Write-Output ""
Write-Output "JSON Results:"

$jsonOutput = $data | ConvertTo-Json -Depth 10

# Output the data
Write-Output $jsonOutput

Execution results:

Contact 78 (Ellena Connor <econnor@company.com>) was created

JSON Results:
{
  "ContactId": 78,
  "FirstName": "Ellena",
  "LastName": "Connor",
  "FullName": "Ellena Connor",
  "EmailAddress": "econnor@company.com",
  "NameAndEmailAddress": "Ellena Connor <econnor@company.com>",
  "PhoneNumber": null,
  "TimeZoneIdentifier": "Central Standard Time",
  "EnableNotifications": false,
  "AllowPortalAccess": false,
  "IsFavorite": false,
  "NumberOfProjects": 0,
  "CreatedByFullName": "Max Miller",
  "CreatedById": "25a34a2f-e3d8-4690-88f5-6b399cf88c4c",
  "CreatedOn": "2024-04-17T14:24:18.4674264+00:00",
  "CreatedBy": null,
  "LastUpdatedByFullName": "Max Miller",
  "LastUpdatedById": "25a34a2f-e3d8-4690-88f5-6b399cf88c4c",
  "LastUpdatedOn": "2024-04-17T14:24:18.4674264+00:00",
  "LastUpdatedBy": null,
  "Fields": [
    {
      "FieldId": 50,
      "ObjectId": 7,
      "DataTypeId": 10,
      "DataTypeName": "Reference",
      "Label": "Skills",
      "IsRequired": false,
      "Position": 0,
      "Guid": 7413322756636,
      "IsSystemField": false,
      "IsReferenceValue": false,
      "DefaultValue": null,
      "CopyPreviousValueOnSaveAndNew": false,
      "Value": null,
      "ReferenceObject": null
    },
    {
      "FieldId": 67,
      "ObjectId": 7,
      "DataTypeId": 1,
      "DataTypeName": "Basic Text",
      "Label": "Office Location",
      "IsRequired": false,
      "Position": 1,
      "Guid": 1756477664260,
      "IsSystemField": false,
      "IsReferenceValue": false,
      "DefaultValue": null,
      "CopyPreviousValueOnSaveAndNew": false,
      "Value": null,
      "ReferenceObject": null
    }
  ]
}

Create a new contact (with custom fields)

# Create a new contact (no custom fields)

# Create an object with the necessary fields to create the contact
# Note: The email field is the only required system field for the contact object

$entry = @{
    EmailAddress    = "dherman@company.com"
    FirstName       = "Danielle"
    LastName        = "Herman"
    Fields          = @(
        @{
            FieldId = 50
            Label   = "Skills"
            Value   = @{
                ReferenceObject = @{
                    Values  = @(
                        @{
                            KeyAsInteger    = 2
                            Value           = "Analytics"
                        }
                    )
                }
            }
        }
        @{
            FieldId = 67
            Label   = "Office Location"
            Value   = @{
                ValueAsString = "Minneapolis"
            }
        }
    )
}

# Create the contact. The created entry will be returned back.
$data = Add-Contact -Entry $entry

# Output some information to help indicate that the contact was created
Write-Output "Contact $($data.ContactId) ($($data.NameAndEmailAddress)) was created"

# For debug purposes, convert the data to output as JSON so we can see all the fields
Write-Output ""
Write-Output "JSON Results:"

$jsonOutput = $data | ConvertTo-Json -Depth 10

# Output the data
Write-Output $jsonOutput

Execution results:

Contact 79 (Danielle Herman <dherman@company.com>) was created

JSON Results:
{
  "ContactId": 79,
  "FirstName": "Danielle",
  "LastName": "Herman",
  "FullName": "Danielle Herman",
  "EmailAddress": "dherman@company.com",
  "NameAndEmailAddress": "Danielle Herman <dherman@company.com>",
  "PhoneNumber": null,
  "TimeZoneIdentifier": null,
  "EnableNotifications": false,
  "AllowPortalAccess": false,
  "IsFavorite": false,
  "NumberOfProjects": 0,
  "CreatedByFullName": "Max Miller",
  "CreatedById": "25a34a2f-e3d8-4690-88f5-6b399cf88c4c",
  "CreatedOn": "2024-04-17T15:06:19.2753792+00:00",
  "CreatedBy": null,
  "LastUpdatedByFullName": "Max Miller",
  "LastUpdatedById": "25a34a2f-e3d8-4690-88f5-6b399cf88c4c",
  "LastUpdatedOn": "2024-04-17T15:06:19.2753792+00:00",
  "LastUpdatedBy": null,
  "Fields": [
    {
      "FieldId": 50,
      "ObjectId": 7,
      "DataTypeId": 10,
      "DataTypeName": "Reference",
      "Label": "Skills",
      "IsRequired": false,
      "Position": 0,
      "Guid": 7413322756636,
      "IsSystemField": false,
      "IsReferenceValue": false,
      "DefaultValue": null,
      "CopyPreviousValueOnSaveAndNew": false,
      "Value": {
        "ObjectFieldValueId": 2178,
        "ObjectFieldId": 50,
        "ObjectId": 7,
        "PrimaryKeyId": 79,
        "ValueAsString": null,
        "ValueAsBoolean": null,
        "ValueAsNumber": null,
        "ValueAsDecimal": null,
        "ValueAsDate": null,
        "ReferenceObject": {
          "ObjectFieldReferenceObjectInstanceId": 326,
          "ObjectFieldValueId": 2178,
          "ObjectId": 16,
          "Object": null,
          "PrimaryObjectId": 7,
          "PrimaryKeyId": 79,
          "KeyType": "Int32",
          "DisplayFormat": "%Name%",
          "IsSystemObject": false,
          "Name": null,
          "NumberOfValues": 1,
          "Values": [
            {
              "ObjectFieldReferenceObjectInstanceValueId": 243,
              "ObjectFieldReferenceObjectInstanceId": 326,
              "KeyAsString": null,
              "KeyAsInteger": 2,
              "KeyAsLong": null,
              "Value": "Analytics"
            }
          ]
        }
      },
      "ReferenceObject": null
    },
    {
      "FieldId": 67,
      "ObjectId": 7,
      "DataTypeId": 1,
      "DataTypeName": "Basic Text",
      "Label": "Office Location",
      "IsRequired": false,
      "Position": 1,
      "Guid": 1756477664260,
      "IsSystemField": false,
      "IsReferenceValue": false,
      "DefaultValue": null,
      "CopyPreviousValueOnSaveAndNew": false,
      "Value": {
        "ObjectFieldValueId": 2179,
        "ObjectFieldId": 67,
        "ObjectId": 7,
        "PrimaryKeyId": 79,
        "ValueAsString": "Minneapolis",
        "ValueAsBoolean": null,
        "ValueAsNumber": null,
        "ValueAsDecimal": null,
        "ValueAsDate": null,
        "ReferenceObject": null
      },
      "ReferenceObject": null
    }
  ]
}


What's Next