Random 500 errors when adding product variants to checkout via API.

lindbergh_usalindbergh_usa Member Posts: 3
edited February 6 in Development

Hi!

We have quite annoying issue with ecom order creation via API.

Approximately 1 out of 20-30 orders we are creating fails to add product variant to checkout. Problem is specific to some of the ProductVariants, though when I compared them to other ProductVariants and related Retail inventory items I couldn't find any difference.

I tried to reach ecom support, but they redirected me here. Hope you will help.


Below is the example of failing session:


Lightspeed requests log.

1. Create checkout
REQUEST

POST:'https://SECRET:[email protected]/us/checkouts.json'

JSON BODY:

{
  "mode": "guest",
  "customer": {
    "gender": "male",
    "birthdate": "1991-09-18",
    "phone": "888-966-1111",
    "mobile": "888-966-1111",
    "email": "[email protected]",
    "password": "SECRET",
    "firstname": "Test",
    "middlename": "",
    "lastname": "Customer",
    "type": "company",
    "company": "Nordstrom"
  },
  "billing_address": {
    "name": "Test Customer",
    "address1": "21 le mans",
    "number": "",
    "zipcode": "92657 CA",
    "city": "newport Coast",
    "region": "California",
    "country": "us",
    "address2": ""
  },
  "shipping_address": {
    "name": "Test Customer",
    "address1": "21 le mans",
    "number": "",
    "zipcode": "92657 CA",
    "city": "newport Coast",
    "region": "California",
    "country": "us",
    "address2": ""
  },
  "comment": "",
  "newsletter": 0,
  "terms": 1,
  "notifications": "false",
  "memo": "Automated API order. Do not process manually."
}

RESPONSE
HTTP CODE: 200
JSON RESPONSE:

{
  'id': 4491477,
  'created_at': '2020-01-23T13:24:21+00:00',
  'updated_at': '2020-01-23T13:24:21+00:00',
  'order_id': null,
  'theme': null,
  'step': 'shipment',
  'mode': 'guest',
  'info': {
    'remote_ip': '52.20.153.66',
    'user_agent': 'WebshopappApi',
    'referral_id': null
  },
  'customer': {
    'gender': 'male',
    'birthdate': '1991-09-18',
    'phone': '888-966-1111',
    'mobile': '888-966-1111',
    'national_id': null,
    'email': '[email protected]',
    'password': 'SECRET',
    'firstname': 'Test',
    'middlename': null,
    'lastname': 'Customer',
    'type': 'company',
    'company': 'Company',
    'vatnumber': null,
    'cocnumber': null,
    'sameaddress': false
  },
  'billing_address': {
    'name': 'Test Customer',
    'company': 'Company',
    'address1': '21 le mans',
    'address2': null,
    'number': null,
    'extension': null,
    'zipcode': '92657 CA',
    'city': 'newport Coast',
    'region': 'California',
    'region_id': 4166,
    'country': 'us'
  },
  'shipping_address': {
    'name': 'Test Customer',
    'company': null,
    'address1': '21 le mans',
    'address2': null,
    'number': null,
    'extension': null,
    'zipcode': '92657 CA',
    'city': 'newport Coast',
    'region': 'California',
    'region_id': 4166,
    'country': 'us'
  },
  'quote': {
    'id': 25902805,
    'price_incl': '0',
    'price_excl': '0',
    'additional_cost': false,
    'totals': {
      'sub_total': '0',
      'taxes': false,
      'grand_total': '0',
      'combined_taxes': false
    },
    'tax_override': false,
    'vat_shifted': false,
    'local_taxes_may_apply': false,
    'weight': 0,
    'volume': 0,
    'colli': 0,
    'products': [],
    'created_at': '2020-01-23T13:24:21+00:00',
    'updated_at': '2020-01-23T13:24:21+00:00'
  },
  'shipment_method': null,
  'payment_method': null,
  'discount': false,
  'comment': 'Comment',
  'newsletter': false,
  'terms': true,
  'notifications': false,
  'memo': 'Automated API order. Do not process manually.',
  'products': [],
  'discount_code': null
}


2. Add product variant to checkout:


REQUEST
POST:'https://SECRET:[email protected]/us/checkouts/4491477/products.json'
JSON BODY:
{
  "variant_id": 28036925,
  "quantity": 1,
  "special_price_incl": 26.0
}

RESPONSE
HTTP CODE: 500
JSON RESPONSE:
{'error': {'code': 500, 'message': 'Could not add product to cart'}}


3 comments

  • lindbergh_usalindbergh_usa Member Posts: 3

    @Leah do you know how can I get in touch with Ecom API support team?

  • LeahLeah Moderator, Lightspeed Staff Posts: 166 moderator

    Hi @lindbergh_usa Sorry for the delay in reply. I am member of the API support team, and we work with all of the products. The error you're seeing may happen when a product has a custom field that is set to "required", among other possibilities. Please PM me the ShopID and the IDs of some of the affected variants and I will take a look and see if I can find the cause.

    Thanks!

    API Support
    Lightspeed HQ
  • lindbergh_usalindbergh_usa Member Posts: 3
    edited February 20

    I am sending you more details here. Tried to PM without any success.

    Account ID: 158097

    Public Ecom url: https://www.lindberghshop.com/


    Example broken product variant: 28036923

    I checked it and couldn't find any required fields.

    And a JSON contents of one of the product variants:

    {    "id": 28036923,    "createdAt": "2018-10-29T21:34:57+00:00",    "updatedAt": "2019-12-02T16:46:34+00:00",    "isDefault": false,    "sortOrder": 2,    "articleCode": "30-70096",    "ean": "5700199783856",    "sku": "",    "hs": null,    "unitPrice": 0,    "unitUnit": null,    "priceExcl": 39.9,    "priceIncl": 39.9,    "priceCost": 0,    "oldPriceExcl": 0,    "oldPriceIncl": 0,    "stockTracking": "enabled",    "stockLevel": 24,    "stockAlert": 5,    "stockMinimum": 0,    "stockSold": 5,    "stockBuyMininum": 1,    "stockBuyMinimum": 1,    "stockBuyMaximum": 10000,    "weight": 0,    "weightValue": "0.000",    "weightUnit": "oz",    "volume": 0,    "volumeValue": 0,    "volumeUnit": "fl_oz",    "colli": 0,    "sizeX": 0,    "sizeY": 0,    "sizeZ": 0,    "sizeXValue": "0.000",    "sizeYValue": "0.000",    "sizeZValue": "0.000",    "sizeUnit": "in",    "matrix": false,    "title": "\"Color: Dk Blue\",\"Size: M\"",    "taxType": "auto",    "image": {      "createdAt": "2019-05-08T20:29:25+00:00",      "updatedAt": "2019-05-08T20:29:25+00:00",      "extension": "jpg",      "size": 153015,      "title": "30-70096frontdkblue",      "thumb": "https://cdn.shoplightspeed.com/shops/620892/files/13801365/50x50x2/30-70096frontdkblue.jpg",      "src": "https://cdn.shoplightspeed.com/shops/620892/files/13801365/30-70096frontdkblue.jpg"    },    "tax": false,    "product": {      "resource": {        "id": 16978549,        "url": "products/16978549",        "link": "https://api.shoplightspeed.com/us/products/16978549.json"      }    },    "movements": {      "resource": {        "id": false,        "url": "variants/movements?variant=28036923",        "link": "https://api.shoplightspeed.com/us/variants/movements.json?variant=28036923"      }    },    "metafields": {      "resource": {        "id": false,        "url": "variants/28036923/metafields",        "link": "https://api.shoplightspeed.com/us/variants/28036923/metafields.json"      }    },    "additionalcost": {      "resource": {        "id": false,        "url": "additionalcosts/",        "link": "https://api.shoplightspeed.com/us/additionalcosts/.json"      }    },    "options": []  }

Sign In or Register to comment.