LiveAgent - Insert campaign member through prechat api using linkToEntity
|Knowledge Article Number||000199217|
|Resolution||LinkToEntity can't be use to populated required fields. In this case CampaignMember.LeadId is a required field and will give you an exception saying that LeadId can't be null. The reason for this is because linkToEntity first inserts the CampaignMember record with LeadId as null, then it updates it with the value from the doCreate:Lead call.
In situations like this you can workaround the issue by inserting the CampaignMember record in the Lead "after insert" trigger. Read our Developer Documentation to find out more about Triggers.