Line item and Variation numbers for orders

I feel like I am having a rather blonde moment.

I am currently attempting to hook up a shopping cart with the orders api.
My testing code is very simple

$lineItems = [];
$modifier = new OrderLineItemModifier();

$lineItem = new OrderLineItem(9);
$lineItems[] = $lineItem;

$squareOrder = new Order(env('SQUARE_LOCATION_ID'));

$body = new CreateOrderRequest();

$response = $this->client->getOrdersApi()->createOrder($body);
if ($response->isSuccess()) {
  echo '<h1 style="color:#0f0">Success</h1>';
} else {
  echo '<h1 style="color:#f00">Fail</h1>';

I am getting the following error response

Item variation with catalog object ID RVNF32KZWOTKBN6PJYPCQCUE not found.

I am getting the variation and item id using the catalogue api
(the below output is from the ‘getVariations() method’

Square\Models\CatalogObject Object
[type:Square\Models\CatalogObject:private] => ITEM_VARIATION
[id:Square\Models\CatalogObject:private] => 6LUBEB7TVB5UCAJFVDJRRLKH
[updatedAt:Square\Models\CatalogObject:private] => 2020-10-15T21:05:09.923Z
[version:Square\Models\CatalogObject:private] => 1602795909923
[isDeleted:Square\Models\CatalogObject:private] => 
[customAttributeValues:Square\Models\CatalogObject:private] => 
[catalogV1Ids:Square\Models\CatalogObject:private] => 
[presentAtAllLocations:Square\Models\CatalogObject:private] => 
[presentAtLocationIds:Square\Models\CatalogObject:private] => Array
        [0] => LSQMZFM7JA493

[absentAtLocationIds:Square\Models\CatalogObject:private] => 
[imageId:Square\Models\CatalogObject:private] => 
[itemData:Square\Models\CatalogObject:private] => 
[categoryData:Square\Models\CatalogObject:private] => 
[itemVariationData:Square\Models\CatalogObject:private] => Square\Models\CatalogItemVariation Object
        [itemId:Square\Models\CatalogItemVariation:private] => RVNF32KZWOTKBN6PJYPCQCUE
        [name:Square\Models\CatalogItemVariation:private] => Regular
        [sku:Square\Models\CatalogItemVariation:private] => 
        [upc:Square\Models\CatalogItemVariation:private] => 
        [ordinal:Square\Models\CatalogItemVariation:private] => 1
        [pricingType:Square\Models\CatalogItemVariation:private] => FIXED_PRICING
        [priceMoney:Square\Models\CatalogItemVariation:private] => Square\Models\Money Object
                [amount:Square\Models\Money:private] => 150
                [currency:Square\Models\Money:private] => USD

        [locationOverrides:Square\Models\CatalogItemVariation:private] => 
        [trackInventory:Square\Models\CatalogItemVariation:private] => 
        [inventoryAlertType:Square\Models\CatalogItemVariation:private] => 
        [inventoryAlertThreshold:Square\Models\CatalogItemVariation:private] => 
        [userData:Square\Models\CatalogItemVariation:private] => 
        [serviceDuration:Square\Models\CatalogItemVariation:private] => 
        [itemOptionValues:Square\Models\CatalogItemVariation:private] => 
        [measurementUnitId:Square\Models\CatalogItemVariation:private] => 

[taxData:Square\Models\CatalogObject:private] => 
[discountData:Square\Models\CatalogObject:private] => 
[modifierListData:Square\Models\CatalogObject:private] => 
[modifierData:Square\Models\CatalogObject:private] => 
[timePeriodData:Square\Models\CatalogObject:private] => 
[productSetData:Square\Models\CatalogObject:private] => 
[pricingRuleData:Square\Models\CatalogObject:private] => 
[imageData:Square\Models\CatalogObject:private] => 
[measurementUnitData:Square\Models\CatalogObject:private] => 
[subscriptionPlanData:Square\Models\CatalogObject:private] => 
[itemOptionData:Square\Models\CatalogObject:private] => 
[itemOptionValueData:Square\Models\CatalogObject:private] => 
[customAttributeDefinitionData:Square\Models\CatalogObject:private] => 
[quickAmountsSettingsData:Square\Models\CatalogObject:private] => 


Am I not getting the ids correctly?


RVNF32KZWOTKBN6PJYPCQCUE is the itemId field (meaning the parent id). What you want is above that, in the id field with the value 6LUBEB7TVB5UCAJFVDJRRLKH, I believe.

so in the documentation for creating orders, it has this

Replace COFFEE_ITEM_ID with your catalog item ID and SMALL_MODIFIER_ID with your catalog item variation ID.

$order_line_item_modifier = new \Square\Models\OrderLineItemModifier();

$modifiers = [$order_line_item_modifier];
$order_line_item = new \Square\Models\OrderLineItem('1');

So are you saying here that both of those ids should be the same?
both for the variation id?

When i have both of the ids as 6LUBEB7TVB5UCAJFVDJRRLKH, or if i swap the ids around i get the following error message

Modifier option with catalog object ID 6LUBEB7TVB5UCAJFVDJRRLKH not found.

Errr, now I’m not sure I’m following. What are you trying to do? In your first post, you shared the error: Item variation with catalog object ID RVNF32KZWOTKBN6PJYPCQCUE not found., which is a real error (RVNF32KZWOTKBN6PJYPCQCUE is an item, not an item variation).

Now you’re showing Modifier option with catalog object ID 6LUBEB7TVB5UCAJFVDJRRLKH not found., which is also a real error (6LUBEB7TVB5UCAJFVDJRRLKH is an item variation, not a modifier option).

The ids need to match whatever object they are. In your above example, it’s creating new objects (so using arbitrary strings as IDs), but it sounds like you already have the objects created since you have the actual IDs. You need to set the id of the OrderLineItemModifier to have an ID of type MODIFIER, and the lineItem needs to have an ID of type ITEM_VARIATION based on your original code.

I guess then I am not sure what ids I am meant to be using and where

From the api documentation, it looks as if i need to use the ITEM_VARIATION id as well as the ITEM id.

My first lot of code pasted is the variation object, which from what i can tell has an id of 6LUBEB7TVB5UCAJFVDJRRLKH and that ITEM_VARIATION belongs to an ITEM with an id of RVNF32KZWOTKBN6PJYPCQCUE

but when plugging them into the code below

$order_line_item_modifier = new \Square\Models\OrderLineItemModifier();

$modifiers = [$order_line_item_modifier];
$order_line_item = new \Square\Models\OrderLineItem('1');

I get

Item variation with catalog object ID RVNF32KZWOTKBN6PJYPCQCUE not found.

but when i swap them around

$order_line_item_modifier = new \Square\Models\OrderLineItemModifier();

$modifiers = [$order_line_item_modifier];
$order_line_item = new \Square\Models\OrderLineItem('1');

i get

Modifier option with catalog object ID 6LUBEB7TVB5UCAJFVDJRRLKH not found.

So really, i just want to know how i can successfully create an order using existing items and item variations as what i am doing is clearly not correct

In the Catalog data model, everything is a Catalog Object and each catalog object has a type, Item, Item Variation, Modifier, etc.

Items are the parent to item variations, for example, the item might be “Fountain Soda” and its variations might be “Small”, “Medium”, “Large”.

All items have at least one variation.

The line items of an order, the product that is bought and sold, is always a variation, you do not ever sell the top level item

Line items may be modified by a modifier which are another type of catalog object. For example, you might have a “light ice” modifier.

In your request payload, you are applying the item_id, a property pointing to the parent of the item variation, as an order line item, which is not correct- you must use the item variation ID for the order line item catalog object ID. Similarly, you are applying an item variation ID as a modifier, which is not correct. If you want to modify the order line item with a modifier, you need the ID of a modifier catalog object, not an item variation.

Ok great, that makes sense.

So can this be done without the modifier line?

If you don’t need a modifier, then yes it can be done without it. If you’re just trying to create an order for a particular item, all you need is the variation. Everything else is extra (modifiers, taxes, discounts, etc).

Ok great, thanks, i shall give that ago

Ok great.

So that worked, and I am now getting a success result, as well as an order id.
I am not seeing them in my order sandbox order dashboard however

Before an order shows up in the dashboard, it needs to be:

  1. Paid for
  2. Have a fulfillment within it.

For more info see here: