Ejemplo n.º 1
0
        /// <summary>
        /// Associate 2 CRM objects. You would use this endpoint to associate a ticket with a contact, or to associate a line item object to a deal
        /// </summary>
        /// <param name="fromid">The ID of the object being associated</param>
        /// <param name="toid">The ID of the object the from object is being associated with</param>
        /// <param name="type">The ID of the association definition</param>
        public async Task Create(long fromid, long toid, AssociationType type)
        {
            JObject request = new JObject {
                ["fromObjectId"] = fromid,
                ["toObjectId"]   = toid,
                ["category"]     = "HUBSPOT_DEFINED",
                ["definitionId"] = (int)type
            };

            await rest.Put <JObject>("crm-associations/v1/associations", request);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// updates properties of a deal
        /// </summary>
        /// <typeparam name="T">type of deal model to update</typeparam>
        /// <param name="dealdata">data to update</param>
        /// <returns>updated deal</returns>
        public async Task <T> Update <T>(T dealdata)
            where T : HubSpotDeal
        {
            EntityModel model = registry.Get(typeof(T));

            JObject request    = new JObject();
            JArray  properties = new JArray();

            foreach (KeyValuePair <string, PropertyInfo> property in model.Properties)
            {
                properties.Add(new JObject {
                    ["name"]  = property.Key,
                    ["value"] = Convert.ToString(property.Value.GetValue(dealdata), CultureInfo.InvariantCulture)
                });
            }

            request["properties"] = properties;

            JObject response = await rest.Put <JObject>($"deals/v1/deal/{dealdata.ID}", request);

            return(ToDeal <T>(response, model));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// updates a company in hubspot
        /// </summary>
        /// <typeparam name="T">type of company</typeparam>
        /// <param name="company">company data to update</param>
        /// <returns>updated company</returns>
        public async Task <T> Update <T>(T company)
            where T : HubSpotCompany
        {
            EntityModel model = registry.Get(typeof(T));

            JObject request    = new JObject();
            JArray  properties = new JArray();

            foreach (KeyValuePair <string, PropertyInfo> property in model.Properties)
            {
                properties.Add(new JObject
                {
                    ["name"]  = property.Key,
                    ["value"] = property.Value.GetValue(company)?.ToString()
                });
            }

            request["properties"] = properties;

            JObject response = await rest.Put($"companies/v2/companies/{company.ID}", request);

            return(ToCompany <T>(response, model));
        }