In OrdersAPI API Explorer, I can see catalog_object_id and name under line_items, but when I use the API in code, I’m not able to access it.
Does the order actually have catalog object line items? If so, could you reply with the order_id
and I’ll take a look on my end?
Yes it does. Order ID is HyjXzPtjmgDtjt0k0LR62SveV
Thanks
Just to clarify, I’m not able to access catalog_object_id, name, etc. in line items and transaction id in tenders, in the object returned from the API.
Hmmm, I tested in Postman and I definitely see the line_items
with catalog_object_id
as well. Could you provide a code snippet of what you’re doing? You definitely should be getting this information.
A snippet of what I'm trying to do:
var body = new SearchOrdersRequest.Builder()
.LocationIds(locationIds)
.Build();
SearchOrdersResponse ordersResult = ordersApi.SearchOrders(body);
if (ordersResult != null)
{
foreach (var orderItem in ordersResult.Orders)
{
var orderObj = new SquareOrder()
{
id = orderItem.Id,
catalog_object_id = orderItem.LineItems., //can't access
program_name = orderItem.LineItems, //can't access
location_id = orderItem.LocationId ?? null,
customer_id = orderItem.CustomerId ?? null,
transaction_id = orderItem.Tenders ?? null, //can't access
added_on = DateTime.Now,
};
db.SquareOrders.Add(orderObj);
}
}
I tried your snippet and it seems to work for more. Although, not all orders will have LineItems
(the order id you provided above, does, though), nor customer_id
, nor tenders
. Tenders will only be present if the order was paid for. Line items will only be present if you explicitly included it in the order request, and same with customer id. Location id should always be present as far as I know (I can definitely see it in mine, I went through several).
I tested the code with your credentials, and I’m seeing LocationId
, LineItems
, and tenders
, so I’m not sure why it would be null for you.
Stephen, my project is not building, I get the below errors for CatalogObjectID, Name and TransactionID.
'IList<OrderLineItem>' does not contain a definition for 'CatalogObjectID' and no accessible extension method 'CatalogObjectID' accepting a first argument of type 'IList<OrderLineItem>' could be found (are you missing a using directive or an assembly reference?)
It looks like you’re trying to access the catalog object ID on the line item list instead of the line item itself. You need to read the data from the line item, like this:
var body = new SearchOrdersRequest.Builder()
.LocationIds(locationIds)
.Build();
SearchOrdersResponse ordersResult = ordersApi.SearchOrders(body);
if (ordersResult != null) {
var firstOrder = ordersResult.Orders[0];
if (firstOrder != null) {
var firstLineItem = firstOrder.LineItems[0];
if (firstLineItem != null) {
var catalogObjectId = firstLineItem.CatalogObjectId;
}
}
}
Aah of course! Thanks for your help!