Hi Dennis,
I need to update some products within line items in some deals.
I created a page where the user will send a spreadsheet and the system will read this spreadsheet and for each product it should:
- Check if the product exists
- If it exists then update all the properties identified in the spreeadsheet that belong to the product
- Then identify which line intem is associated with the product and update the properties of that item if necessary
- Then identify which deal is associated with the line item and update the properties of that deal if necessary
I set up an API where I filter by the product id and make sure it exists using the endpoint Product - Search and update the properties of product.
But in the sequence I can´t evolve because I didn´t find a way to link the product with the line item or the deal.
Exemple:
<cfif StructKeyExists(form, "NomeArquivo")>
<!--- Passando o arquivo para o servidor --->
<cffile action = "upload" fileField = "NomeArquivo" destination = "#expandpath('.')#\HubSpot\ImportarPlanilha\" nameConflict = "overwrite" result = "arquivo">
<!--- Lendo o arquivo em uma variável --->
<cffile action = "read" file = "#expandpath('.')#\HubSpot\ImportarPlanilha\#arquivo.serverfile#" variable = "meuCSV">
<!--- Array com o conteúdo da linha --->
<cfset aLinha = ArrayNew("1")>
<!--- Extraindo o conteudo do arquivo --->
<cfloop index = "linha" list = "#meuCSV#" delimiters = "#chr(10)##chr(13)#">
<cfif len(trim(replace(linha,";","")))>
<cfset aLinha = ListToArray(linha,";","true")>
<cfif arrayLen(aLinha)>
<!---dados para consultar se o produto existe --->
<cfsavecontent variable = "dadosJSON">
{
"after": "0",
"filterGroups": [
{
"filters": [
{
"operator": "EQ",
"propertyName": "id",
"value": "<cfoutput>#aLinha[1]#</cfoutput>"
}
]
}
],
"limit": "20",
"properties": [
"string"
],
"query": ""
}
</cfsavecontent>
<!--- Monta o componente de controle --->
<cfset cfcHubSpot = new HubSpot()>
<!--- Usa a função de consulta do componente --->
<cfset consultaProduto = cfcHubSpot.consultaServico(
metodoServico:"post",
body:dadosJSON
)>
<cfif consultaProduto.codigo EQ 200>
<!--- dados para alteração dos campos do produto localizado --->
<cfsavecontent variable = "dadosJSON_Update">
{
"archived": false,
"properties": { <!--- Última modificação (Timespam with timezone) --->
"hs_lastmodifieddate": "<cfoutput>#DateFormat(now(),"YYYY-MM-DDThh:mm:ss.sTZD")#</cfoutput>",
<!--- Custo unitário - quanto os produtos vendidos custaram para os clientes, numérico --->
"hs_cost_of_goods_sold": "<cfoutput>#aLinha[3]#</cfoutput>",
<!--- Nome, texto --->
"name": "<cfoutput>#aLinha[6]#</cfoutput>",
<!--- Descrição - Descrição completa do produto, texto --->
"description": "<cfoutput>#aLinha[14]#</cfoutput>"
.
.
.
},
"updatedAt": "<cfoutput>#DateFormat(now(),"YYYY-MM-DDThh:mm:ss.sTZD")#</cfoutput>"
}
</cfsavecontent>
<cfset AtualizaProduto = cfcHubSpot.atualizaProduto(
metodoServico:"PATCH",
body:dadosJSON_Update
)>
<cfif AtualizaProduto.codigo EQ 200>
line item ???
deal ???
<cfelse>
<cfdump var = "#AtualizaProduto#" label="Temos problemas com a atualização">
<cfexit>
</cfif>
<cfelse>
<cfdump var = "#consultaProduto#" label="Temos problemas com a consulta">
<cfexit>
</cfif>
<cfelse>
<cfexit>
</cfif>
<cfelse>
<cfexit>
</cfif>
</cfloop>
</cfif>