Search in v3 API using the externalObjectId value that was set via v2 api using e-commerce sync mess


As I understand it, previously we could create contacts, deals and other records using

PUT /extensions/ecomm/v2/sync/messages

Where you can use externalObjectId = objectId from my system

And now this api is obsolete.

So, we need to use api v3, for example this request to update deals,

PATCH/crm/v3/objects/deals/{dealId}

And the main question is:

Can I find old records that were created by

PUT /extensions/ecomm/v2/sync/messages

using the value stored in externalObjectId?

Example:

Previously, we created a contact record in HubSpot using:

PUT /extensions/ecomm/v2/sync/messages with “externalObjectId”: “1234”,

and in my database the contact has id=1234

{
 "storeId": "example-store-id",
 "objectType": "CONTACT",
 "messages": [
 {
 "action": "UPSERT",
 "changedAt": "1553486400000",
 "externalObjectId": "1234",
 "properties": {
 "firstname": "Jeff",
 "lastname": "David",
 "email": "test@example.com"
 },
 "associations": {
 "DEAL": [
 "example_dealId"
 ]
 }
 }
 ]
}

Is it possible to find this entry using only ID=1234 and using the v3 API?

(prev topic is https://community.hubspot.com/t5/APIs-Integrations/Search-in-v3-API-using-externalObjectId/m-p/760016#M61625)

Hi, is it possible to use externalObjectId to search in v3 API?
For example, we previously used this query
https://api.hubapi.com/extensions/ecomm/v2/sync/messages

with this body (example for product):

{

**action: action,**

**externalObjectId: obj.id,**

   **properties: {**

      **price: obj.price \|\| 0,**

      **name: obj.name \|\| '',**

      **description: obj.description \|\| '',**

      **hs\_sku: obj.sku \|\| '',**

   **}

}**

Or maybe we need to use a different way to match old and new data?

Thanks for help!

Hello,

the V3 Search API is really powerfull. You can filter the search result for any property.

Check out the documentation page for more information: Search the CRM - HubSpot docs

You basically POST to `/crm/v3/objects/<YOUR_OBJECT_TYPE_HERE>/search`, and in the post body, you can then apply your filters. Taken the example from the documentation for searching a contact, the request would look like this:

POST https://api.hubapi.com/crm/v3/objects/contacts/search
Authorization: Bearer {{apiToken}}
Content-Type: application/json

{
 "filterGroups":[
 {
 "filters":[
 {
 "propertyName": "firstname",
 "operator": "EQ",
 "value": "Alice"
 }
 ]
 }
 ]
}

Thanks for your reply, yes, I understand that I can use name etc.

But can I use externalObjectId for this purpose?

For example, I have two products with the same name, but only the externalObjectId is different.
And as I understand it, this code will not work

{
 "filterGroups":[
 {
 "filters":[
 {
 "propertyName": "externalObjectId",
 "operator": "EQ",
 "value": "1010101"
 }
 ]
 }
 ]
}

Do you mean line-items instead of products?

In my understanding a line-items “externalObjectId” refers to the products “hs_object_id”. You can search products for “hs_object_id” and use your “externalObjectId” as object id.
So maybe try:

{
 "filterGroups":[
 {
 "filters":[
 {
 "propertyName": "hs_object_id",
 "operator": "EQ",
 "value": "1010101"
 }
 ]
 }
 ]
}

Hmm, to clarify.

The hs_object_id in deals, line_items, products, contacts are equal to externalObjectId form this request?

{

**action: action,**

**externalObjectId: obj.id,**

   **properties: {**

   **price: obj.price \|\| 0,**

   **name: obj.name \|\| '',**

   **description: obj.description \|\| '',**

   **hs\_sku: obj.sku \|\| '',**

**}**

}

Since this field is currently read-only, it equals id

{
“id”: “17501”,
“properties”: {
“company”: “Biglytics”,
“createdate”: “2023-02-23T11:00:45.448Z”,
“email”: “bcooper@biglytics.net”,
“firstname”: “Bryan”,
“hs_all_contact_vids”: “17501”,
…
“hs_object_id”: “17501”,
“hs_pipeline”: “contacts-lifecycle-pipeline”,
“hs_searchable_calculated_phone_number”: “8779290687”,
…
“website”: “http://biglytics.net”
},
“createdAt”: “2023-02-23T11:00:45.448Z”,
“updatedAt”: “2023-02-23T11:00:45.448Z”,
“archived”: false
}

The request you posted isn’t for searching, is it?

May i ask what are you trying to do?
Do you want to get the object that is referenced by the externalObjectId, or do you want to get all records, which has the same externalObjectId?

But generally speaking, yes.

externalObjectId seems to refer to an external object.
And you can use this externalObjectId to get this specific resource if you use this as hs_object_id and get the referenced object.
So for example, if i create a line-item, it references to a product. So the line-items externalObjectId [edit: hs_product_id] is the products hs_object_id. Keep in mind that there could be several line-items referencing to the same product.

But in my understanding, there is no externalObjectId,so in case of product-line-item, the property would be hs_product_id.

I’m trying to find records that were created in the old api via https://api.hubapi.com/extensions/ecomm/v2/sync/messages
and we used externalObjectId = recordId in our system

For example externalObjectId = order.id

And now we’re moving to the v3 api, and I need to match records.

And the only source of truth that I can use for a 100% guarantee is externalObjectId, because we passed it equal to the record id in our system.

And just to clarify, before, when we used extensions/ecomm/v2/sync/messages, when we sent something like this

{
 "storeId": "example-store-id",
 "objectType": "CONTACT",
 "messages": [
 {
 "action": "UPSERT",
 "changedAt": "1553486400000",
 "externalObjectId": "1234",
 "properties": {
 "firstname": "Jeff",
 "lastname": "David",
 "email": "test@example.com"
 },
 "associations": {
 "DEAL": [
 "example_dealId"
 ]
 }
 }
 ]
}

in this case, Hubspot set hs_object_id = externalObjectId

And I can use this query to find, for example, all the transactions that we have in both systems.

{
 "filterGroups":[
 {
 "filters":[
 {
 "propertyName": "hs_object_id",
 "operator": "IN",
 "values": [id1, id2, ... ]
 }
 ]
 }
 ]
}

So you have externalObjectId as a custom property, and want to find a record with this property set to a specific value?

Then your proposed request should work just fine:

POST https://api.hubapi.com/crm/v3/objects/{{objectType}}/search
Authorization: Bearer {{apiToken}}
Content-Type: application/json

{
 "properties": ["externalObjectId"],
 "filterGroups":[
 {
 "filters":[
 {
 "propertyName": "externalObjectId",
 "operator": "EQ",
 "value": "{{externalObjectId}}"
 }
 ]
 }
 ]
}

@enrico_baskey wrote:

So you have externalObjectId as a custom property, and want to find a record with this property set to a specific value?


No, this property is from Hubspot.

As I understand it, previously we could create contacts, deals and other records using

PUT /extensions/ecomm/v2/sync/messages

Where you can use externalObjectId = objectId from my system

And now this api is obsolete.

So, we need to use api v3, for example this request to update deals,

PATCH/crm/v3/objects/deals/{dealId}

And the main question is:

Can I find old records that were created by

PUT /extensions/ecomm/v2/sync/messages

using the value stored in externalObjectId?

Example:

Previously, we created a contact record in HubSpot using:

PUT /extensions/ecomm/v2/sync/messages with “externalObjectId”: “1234”,

and in my database the contact has id=1234

{
 "storeId": "example-store-id",
 "objectType": "CONTACT",
 "messages": [
 {
 "action": "UPSERT",
 "changedAt": "1553486400000",
 "externalObjectId": "1234",
 "properties": {
 "firstname": "Jeff",
 "lastname": "David",
 "email": "test@example.com"
 },
 "associations": {
 "DEAL": [
 "example_dealId"
 ]
 }
 }
 ]
}

Is it possible to find this entry using only ID=1234 and using the v3 API?

Hello @DOpanovich
Hope for the best! Try this to find the record you created using the v2 API with the externalObjectId value of “1234” using the v3 API.

use the following endpoint to search for contacts based on their external ID:

GET /crm/v3/objects/contacts/search include a query parameter in the URL that specifies the external ID you are searching for, like this:

GET /crm/v3/objects/contacts/search?query=1234

This will return a list of all contacts that have an external ID of “1234”. If your contact was created using the v2 API with this external ID, it should appear in the results.

Keep in mind that the v3 API uses a different object model than the v2 API, so the properties and associations of your record might be stored differently in the v3 API. You will need to check the documentation for the v3 API to see how to access and update these values. If this works please let me know

Thanks for the reply.

But v3 api search requires body params and also works throw POST request.

and according to the documents, I’m not sure it will search by externalObjectId

you can check for any alternate way for mapping your data. You can use the email property for contacts and the SKU property for products and other object fields likewise.

Hi, @DOpanovich. Thanks for reaching out. I’m going to merge your previous post into this one to help keep things tidy.

Hey, @himanshurauthan has your team handled anything similar in the past?

Thank you! — Jaycee