Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Tag/ Get all Tag / Get Tag by Name #48

Open
lemieuxs opened this issue Dec 9, 2016 · 2 comments
Open

Create Tag/ Get all Tag / Get Tag by Name #48

lemieuxs opened this issue Dec 9, 2016 · 2 comments

Comments

@lemieuxs
Copy link

lemieuxs commented Dec 9, 2016

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

@hfloyd
Copy link
Contributor

hfloyd commented Feb 8, 2017

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!

@maheshmilinda
Copy link

Thanks for the code , it really helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants