Apr 28, 2022 2:18 PM - edited Apr 28, 2022 2:28 PM
Hi everybody, hope everythings going well!
This is my situacion, Im sending lead info from my webpage to hubspot using python. the thing is, some properties doesnt need to be overwrited.
E.g. someone is looking product in my website, so he sends a request and i receive it and send it to hubspot, then he goes to other option that he likes it too and sends a request with the second option and its the same as the first request, what i hoping to see in hubspot its 1 contact with a field that says tha he likes option 1 and 2.
Theres one las ting to get in mind, not all properties gonna be appended, in the above case, i need that email, phone, cityt, etc be overwritted in each request
Is there some doc that i can look for, or theres somethin im missing that is overwriting each time that a contact sends a request?
thanks in advance, have a great week
Solved! Go to Solution.
May 2, 2022 2:10 AM
I wrote this real quick, but it retrieves the properties of the contact and checks if it includes the new value. If not, it adds the value and updates the contact. If you use an API key instead of a private app token, remove the 'authorization' header and add the API key to the URL.
let needToUpdate = false
const getCurrentContact = async (contactId, token) => {
return axios({
method: 'get',
url: `https://api.hubapi.com/crm/v3/objects/contacts/${contactId}?properties=project_names&properties=suppliers&properties=prices`,
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
}).then((response) => {
if (response.data.properties) {
return response.data.properties
} else {
return false
}
}).catch((error) => {
console.log(`Error while retrieving contact: ${error.response.data.message}`)
return false
})
}
const updateContact = async (contactProperties, contactId, token) => {
const data = contactProperties
return axios({
method: 'patch',
url: `https://api.hubapi.com/crm/v3/objects/contacts/${contactId}`,
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
data: JSON.stringify(data)
}).then((response) => {
return response
}).catch((error) => {
console.log(`Error while updating contact: ${error.response.data.message}`)
return false
})
}
const currentContactProperties = await getCurrentContact(contactId, token)
if (!currentContactProperties.project_names.includes(myNewProjectValue)) {
currentContactProperties.project_names.push(myNewProjectValue)
needToUpdate = true
}
if (!currentContactProperties.suppliers.includes(myNewSupplierValue)) {
currentContactProperties.suppliers.push(myNewSupplierValue)
needToUpdate = true
}
if (!currentContactProperties.prices.includes(myNewPricesValue)) {
currentContactProperties.prices.push(myNewPricesValue)
needToUpdate = true
}
if (needToUpdate) {
const updatedContact = await updateContact(currentContactProperties, contactId, token)
console.log(updatedContact)
}
May 13, 2022 6:42 AM
@Teun wrote:
I wrote this real quick, but it retrieves the properties of the contact and checks if it includes the new value. If not, it adds the value and updates the contact. If you use an API key instead of a private app token, remove the 'authorization' header and add the API key to the URL.
let needToUpdate = false
const getCurrentContact = async (contactId, token) => {
return axios({
method: 'get',
url: `https://api.hubapi.com/crm/v3/objects/contacts/${contactId}?properties=project_names&properties=suppliers&properties=prices`,
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
}).then((response) => {
if (response.data.properties) {
return response.data.properties
} else {
return false
}
}).catch((error) => {
console.log(`Error while retrieving contact: ${error.response.data.message}`)
return false
})
}
const updateContact = async (contactProperties, contactId, token) => {
const data = contactProperties
return axios({
method: 'patch',
url: `https://api.hubapi.com/crm/v3/objects/contacts/${contactId}`,
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
data: JSON.stringify(data)
}).then((response) => {
return response
}).catch((error) => {
console.log(`Error while updating contact: ${error.response.data.message}`)
return false
})
}
const currentContactProperties = <a href="https://apkkernal.com/prequel-mod-apk/">prequel</a> getCurrentContact(contactId, token)
if (!currentContactProperties.project_names.includes(myNewProjectValue)) {
currentContactProperties.project_names.push(myNewProjectValue)
needToUpdate = true
}
if (!currentContactProperties.suppliers.includes(myNewSupplierValue)) {
currentContactProperties.suppliers.push(myNewSupplierValue)
needToUpdate = true
}
if (!currentContactProperties.prices.includes(myNewPricesValue)) {
currentContactProperties.prices.push(myNewPricesValue)
needToUpdate = true
}
if (needToUpdate) {
const updatedContact = await updateContact(currentContactProperties, contactId, token)
console.log(updatedContact)
}
Thankyou so much it helped me also. Finally i ran it without getting any errors.
Apr 29, 2022 2:44 PM - edited Apr 29, 2022 2:45 PM
Hi @dennisedson ,
Like Dennis said, you might want to use a checkbox or even a multiselect. If you go for a multiselect, you need a function to check if the option is present, and if not, add it.
You could also go for a single-line text, but in that case, you would also need to first retrieve the contact and the property you want to append a value to and add the value instead.
I am not great with Python, but could share some NodeJS examples.
Apr 29, 2022 3:23 PM - edited Apr 29, 2022 5:18 PM
Im needing the checkbox option, well I guess. Using some king of json sintax, this is what i need at the end of the day:
name: jhon
last_name: perez
city: virgia beach
state: VA
project_names: ["12x30 barn", "18x22 metal garage", "12 x 25 carport"]
Suppliers: ["Alans factory", "catapult steel buildings", "UMB"]
prices: ["2000", "49000", 50000"]
would be great if you can share with me the NodeJs example, thanks my man, appreciated it!!!
May 2, 2022 2:10 AM
I wrote this real quick, but it retrieves the properties of the contact and checks if it includes the new value. If not, it adds the value and updates the contact. If you use an API key instead of a private app token, remove the 'authorization' header and add the API key to the URL.
let needToUpdate = false
const getCurrentContact = async (contactId, token) => {
return axios({
method: 'get',
url: `https://api.hubapi.com/crm/v3/objects/contacts/${contactId}?properties=project_names&properties=suppliers&properties=prices`,
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
}).then((response) => {
if (response.data.properties) {
return response.data.properties
} else {
return false
}
}).catch((error) => {
console.log(`Error while retrieving contact: ${error.response.data.message}`)
return false
})
}
const updateContact = async (contactProperties, contactId, token) => {
const data = contactProperties
return axios({
method: 'patch',
url: `https://api.hubapi.com/crm/v3/objects/contacts/${contactId}`,
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
data: JSON.stringify(data)
}).then((response) => {
return response
}).catch((error) => {
console.log(`Error while updating contact: ${error.response.data.message}`)
return false
})
}
const currentContactProperties = await getCurrentContact(contactId, token)
if (!currentContactProperties.project_names.includes(myNewProjectValue)) {
currentContactProperties.project_names.push(myNewProjectValue)
needToUpdate = true
}
if (!currentContactProperties.suppliers.includes(myNewSupplierValue)) {
currentContactProperties.suppliers.push(myNewSupplierValue)
needToUpdate = true
}
if (!currentContactProperties.prices.includes(myNewPricesValue)) {
currentContactProperties.prices.push(myNewPricesValue)
needToUpdate = true
}
if (needToUpdate) {
const updatedContact = await updateContact(currentContactProperties, contactId, token)
console.log(updatedContact)
}
May 2, 2022 9:29 AM
Thank you so much my man, really appreciated it!!! this everything im needing!!!
May 2, 2022 9:34 AM
Apr 29, 2022 11:53 AM
@rechavar , I believe the property field type that you would want to use is a checkbox.
See here for more info on properties
You can patch that property, but when you patch it, you will need to include all checked options in the new request. If you only include the newest, the older one will be removed.
@taran42 any suggestions from your end?
Apr 29, 2022 2:42 PM
Ohhh thanks, ill try it and if it workz im gonna accept it as Solution, but, just to be clear, at the end of the day im gonna see in hubspot something like this?(where you see lists "[]" its mean that the info in that field needs to be append):
name: jhon
last_name: perez
city: virgia beach
state: VA
project_names: ["12x30 barn", "18x22 metal garage", "12 x 25 carport"]
Suppliers: ["Alans factory", "catapult steel buildings", "UMB"]
prices: ["2000", "49000", 50000"]
thank you so much for your answer!! appreciated it