APIs & Integrations

Mahesh1250
Contributor

Line_items are not creating every time via eCommerce Bridge API

SOLVE

Hi Experts,

 

While creating DEAL via eCommerce Bridge API, LINE_ITEMS are not creating every time. sometimes it works 1 out of 5 times. Why it's behaving this way?

 

Please see the process I'm following and suggest me the solution.

 

Step # 1: creating Contact with externalObjectID

 

{
  "storeId": "ecommercebridge-deviceb2b-store",
  "objectType": "CONTACT",
  "messages": [
    {
      "action": "UPSERT",
      "changedAt": 1575522058436,
      "externalObjectId": "test@test.com",
      "properties": {
        "email": "test@test.com"
      }
    }
  ]
}

 Step #2: Creating DEAL & associate with CONTACT

{
  "storeId": "ecommercebridge-deviceb2b-store",
  "objectType": "DEAL",
  "messages": [
    {
      "action": "UPSERT",
      "changedAt": 1575522058736,
      "externalObjectId": "deal_0000735706",
      "properties": {
        "dealname": "Deal 0000735706",
        "dealstage": "processed",
        "closedate": 1575522058736,
        "amount": 18,
        "sapordernumber": "0000735706",
        "companyname": "xxxx xxx xx xxxx",
        "createdate": 1575522058736
      },
      "associations": {
        "CONTACT": [
          "test@test.com"
        ]
      }
    }
  ]
}

Step #3: Creating PRODUCT with externalObjectID

{
  "storeId": "ecommercebridge-deviceb2b-store",
  "objectType": "PRODUCT",
  "messages": [
    {
      "action": "UPSERT",
      "changedAt": 1575522059010,
      "externalObjectId": "xx-SM-060",
      "properties": {
        "product_name": "Koo Air Cushion Anaesthetic Masks - Size 0",
        "product_description": "xxxx"
      }
    },
    {
      "action": "UPSERT",
      "changedAt": 1575522059010,
      "externalObjectId": "xx-SM-062B",
      "properties": {
        "product_name": "xxxx"
      }
    },
    {
      "action": "UPSERT",
      "changedAt": 1575522059010,
      "externalObjectId": "xx-AM03",
      "properties": {
        "product_name": "xxxx"
      }
    }
  ]
}

Step #4: Creating LINE_ITEM and associate with PRODUCT & DEAL

{
  "storeId": "ecommercebridge-deviceb2b-store",
  "objectType": "LINE_ITEM",
  "messages": [
    {
      "action": "UPSERT",
      "changedAt": 1575522059307,
      "externalObjectId": "lineItem_xx-SM-060",
      "properties": {
        "product_name": "Koo Air Cushion Anaesthetic Masks - Size 0",
        "product_description": "xxxx",
        "quantity": 1,
        "price": 3,
        "amount": 3,
        "createdate": 1575522059307
      },
      "associations": {
        "DEAL": [
          "deal_0000735706"
        ],
        "PRODUCT": [
          "xx-SM-060"
        ]
      }
    },
    {
      "action": "UPSERT",
      "changedAt": 1575522059307,
      "externalObjectId": "lineItem_xx-SM-062B",
      "properties": {
        "product_name": "Koo Air Cushion Anaesthetic Masks - Size 2 - Bubblegum",
        "product_description": "xxxx",
        "quantity": 2,
        "price": 3,
        "amount": 6,
        "createdate": 1575522059307
      },
      "associations": {
        "DEAL": [
          "deal_0000735706"
        ],
        "PRODUCT": [
          "xx-SM-062B"
        ]
      }
    },
    {
      "action": "UPSERT",
      "changedAt": 1575522059307,
      "externalObjectId": "lineItem_xx-AM03",
      "properties": {
        "product_name": "Well Lead Air Cushion Disposable Anaesthesia Mask - Size 3",
        "product_description": "xxxx",
        "quantity": 3,
        "price": 3,
        "amount": 9,
        "createdate": 1575522059307
      },
      "associations": {
        "DEAL": [
          "deal_0000735706"
        ],
        "PRODUCT": [
          "xx-AM03"
        ]
      }
    }
  ]
}

With the above code, DEAL got created with empty LINE_ITEMS. Please suggest me what's going wrong.

 

Thanks,

Mahesh.S

 

 

0 Upvotes
1 Accepted solution
Mahesh1250
Solution
Contributor

Line_items are not creating every time via eCommerce Bridge API

SOLVE

Hi @jackcoldrick,

 

Thanks for the response... We got a solution for this as stated below.

 

I'm creating LINEITEM with externalObjectID as "Lineitem_" + xx123 (here xx123 is productCode). So, here there is a chance of getting duplicates if I order the same product(xx123) in another Order - so, it's not creating a new Line-item for new Deal.

 

Now, I fixed by adding an order code to it to make it unique every time.  Like

Lineitem_productCode_orderCode

 

LineItem : 

Lineitem_xx123_00012345

 

{
    "storeId": "store-1",
    "objectType": "LINE_ITEM",
    "messages": [
        {
            "action": "UPSERT",
            "changedAt": "1575522059307",
            "externalObjectId": "Lineitem_xx12345_0012345",
            "properties": {
                "external_price": 100,
                "external_quantity": 2
            },
            "associations": {
                "DEAL": [
                    "deal_0000735706"
                ],
                "PRODUCT": [
                    "PRODUCT001"
                ]
            }
        },
        {
            "action": "UPSERT",
            "changedAt": "1575522059307",
            "externalObjectId": "Lineitem_xx12326_0012345",
            "properties": {
                "external_price": 100,
                "external_quantity": 1
            },
            "associations": {
                "DEAL": [
                    "deal_0000735706"
                ],
                "PRODUCT": [
                    "PRODUCT002"
                ]
            }
        }
    ]
}

Thanks for HubSpot Technical Support Team(& Abigail Chia)...Great Support.

 

Thanks,

Mahesh.S

View solution in original post

2 Replies 2
jackcoldrick
HubSpot Employee
HubSpot Employee

Line_items are not creating every time via eCommerce Bridge API

SOLVE

Hi @Mahesh1250,

 

Thanks for the detailed post this helps a lot. I've looked through it and I cannot see anything immediately wrong with what you are sending into HubSpot. I've also recreated your test using the same timestamps and I am seeing line items being created on my order (see below):

 

line-item-on-deal.png

 

The above is the result of the following PUT request:

 

ENDPOINT (send sync message):

 

https://api.hubapi.com/extensions/ecomm/v2/sync/messages?hapikey={{apikey}}

 

 

PAYLOAD:

 

{
    "storeId": "store-1",
    "objectType": "LINE_ITEM",
    "messages": [
        {
            "action": "UPSERT",
            "changedAt": "1575522059307",
            "externalObjectId": "LINEITEMX101",
            "properties": {
                "external_price": 100,
                "external_quantity": 2
            },
            "associations": {
                "DEAL": [
                    "deal_0000735706"
                ],
                "PRODUCT": [
                    "PRODUCT001"
                ]
            }
        },
        {
            "action": "UPSERT",
            "changedAt": "1575522059307",
            "externalObjectId": "LINEITEMX102",
            "properties": {
                "external_price": 100,
                "external_quantity": 1
            },
            "associations": {
                "DEAL": [
                    "deal_0000735706"
                ],
                "PRODUCT": [
                    "PRODUCT002"
                ]
            }
        }
    ]
}

 

 

My recommendation at this point would be to use the "Check sync status of an object" endpoint to ensure the LINE ITEMS are being correctly associated to the deal. This is assuming that you are seeing blank LINE ITEMS on the DEAL object. Your request would look something like this:

 

ENDPOINT: 

 

 

GET https://api.hubapi.com/extensions/ecomm/v2/sync/status/store-1/LINE_ITEM/lineItem_xx-SM-060?hapikey={{apikey}}

 

 

If there has been an error, it will appear in the errors array in the response and an erroredAt field will be present. If you could share this error (if any) for the 3 line items you are attempting to create that would be great!

 

Regards,

Jack

 

Jack Coldrick
Solutions Engineer @ HubSpot
Add me on LinkedIn
Mahesh1250
Solution
Contributor

Line_items are not creating every time via eCommerce Bridge API

SOLVE

Hi @jackcoldrick,

 

Thanks for the response... We got a solution for this as stated below.

 

I'm creating LINEITEM with externalObjectID as "Lineitem_" + xx123 (here xx123 is productCode). So, here there is a chance of getting duplicates if I order the same product(xx123) in another Order - so, it's not creating a new Line-item for new Deal.

 

Now, I fixed by adding an order code to it to make it unique every time.  Like

Lineitem_productCode_orderCode

 

LineItem : 

Lineitem_xx123_00012345

 

{
    "storeId": "store-1",
    "objectType": "LINE_ITEM",
    "messages": [
        {
            "action": "UPSERT",
            "changedAt": "1575522059307",
            "externalObjectId": "Lineitem_xx12345_0012345",
            "properties": {
                "external_price": 100,
                "external_quantity": 2
            },
            "associations": {
                "DEAL": [
                    "deal_0000735706"
                ],
                "PRODUCT": [
                    "PRODUCT001"
                ]
            }
        },
        {
            "action": "UPSERT",
            "changedAt": "1575522059307",
            "externalObjectId": "Lineitem_xx12326_0012345",
            "properties": {
                "external_price": 100,
                "external_quantity": 1
            },
            "associations": {
                "DEAL": [
                    "deal_0000735706"
                ],
                "PRODUCT": [
                    "PRODUCT002"
                ]
            }
        }
    ]
}

Thanks for HubSpot Technical Support Team(& Abigail Chia)...Great Support.

 

Thanks,

Mahesh.S