Open lemieuxs opened 7 years ago
Hi @lemieuxs, I am new to this, but I had a similar need... Not fully tested yet, but I do have this code:
public IEnumerable<ContactGroup> GetAllTags()
{
var tags = _connectionClient.DataService.Query<ContactGroup>();
return tags;
}
public int GetTagId(string TagName, bool CreateIfNoMatch = false)
{
var tagId = 0;
var allIsTags = this.GetAllTags();
var matchingTags = allIsTags.Where(n => n.GroupName == TagName).ToList();
if (matchingTags.Any())
{
//Assume first tag if more than one
tagId = Int32.Parse(matchingTags.First().Id);
}
else
{
if (CreateIfNoMatch)
{
//Create new tag and return Id
var description = string.Format("Auto-created by Website InfusionsoftService code [{0}].", DateTime.Now.ToLongTimeString());
tagId = _connectionClient.DataService.Add<ContactGroup>(setter =>
{
setter.Set(t => t.GroupName, TagName);
setter.Set(t => t.GroupDescription, description);
});
}
}
return tagId;
}
Let me know how it goes!
Thanks for the code , it really helps
Hi, I am trying to add customer using your wrapper, but I don't seem to be able to find a way to either create dynamically a new Tag / Group or to retreive existing Tag / Group.
Any help would be really appreciated !
Have a good one !
Sebastien