Square Order Discounts

I am currently using the .NET SDK. I am trying to get all of the discounts for a portal, but I am seeing there are discounts embedded in the “order” object that are not a “discount”. Is this by design or am I missing something?

var objectTypes = new List<string>();
	objectTypes.Add("discount");

	var body = new SearchCatalogObjectsRequest.Builder()
			.ObjectTypes(objectTypes)
			.IncludeDeletedObjects(true)
			//.Limit(100)
			.Cursor(cursor)
			.Build();

	var result = await client.CatalogApi.SearchCatalogObjectsAsync(body: body);

Thanks in advance!

Are these ad hoc discounts that aren’t actual discounts in the item catalog? :slightly_smiling_face:

They are not ad-hoc discounts. The names of the discounts match but the discount id in the order does not match a catalog id or a discount id from the catalog objects.

Do you have some examples that we can look at? :slightly_smiling_face:

From The Order

{
				"uid": "3F5152F6-DA7F-4C55-AA55-9D96496024A5",
				"catalog_object_id": "D5UVHKI3QXESIIU6PUX7BPZW",
				"catalog_version": 1687454729408,
				"name": "300251 ISC EMP",
				"percentage": "20",
				"applied_money": {
					"amount": 1200,
					"currency": "USD"
				},
				"type": "FIXED_PERCENTAGE",
				"scope": "ORDER"
			}

This is when I try to get that “catalog” object from postman

{
    "errors": [
        {
            "category": "INVALID_REQUEST_ERROR",
            "code": "NOT_FOUND",
            "detail": "Catalog object with ID `D5UVHKI3QXESIIU6PUX7BPZW` not found."
        }
    ]
}

Looking at the API Logs there is one GET request to RetrieveCatalogObject for that ID. That endpoint doesn’t include_deleted_objects which is why you got the error. I verified with the POST request of BatchRetrieveCatalogObjects and include_deleted_objects that the discount is returned. :slightly_smiling_face:

I ran it through the SDK with include_deleted_objects set to true and that ID did not return, here is an example of what did return

{
		"type": "DISCOUNT",
		"id": "7PB3Z4A3UYPL4WFGQIDBBYQ7",
		"updated_at": "2020-06-23T20:17:44.297Z",
		"version": 1592943464297,
		"is_deleted": true,
		"present_at_all_locations": true,
		"discount_data": {
			"name": "10% Hard Card",
			"discount_type": "FIXED_PERCENTAGE",
			"percentage": "10.0",
			"modify_tax_basis": "MODIFY_TAX_BASIS"
		}
	}

I feel like I am missing something. Please let me know if you want more details to help me figure this out :slight_smile:

The API Logs that I checked show that it was a RetrieveCatalogObject API call. Are you sure it was a call to SearchCatalogObjects that didn’t return the results? Can you confirm in our Logs? :slightly_smiling_face:

I think I am calling the right one. Here is the code

var body = new SearchCatalogObjectsRequest.Builder()
                                .ObjectTypes(objectTypes)
                                .IncludeDeletedObjects(includeDeleted)
                                //.Limit(100)
                                .Cursor(cursor)
                                .Build();

                        var result = await client.CatalogApi.SearchCatalogObjectsAsync(body: body);

Chastise me if I am wrong :frowning:

That is the right call except I don’t see any API call in the logs from that function. Whats your application ID so I can make sure I’m checking the right account. Also when did you last run that function? :slightly_smiling_face:

Where would I find the application ID? I am just a lowly developer so I do not have access to dashboards.

You’ll need access to the Developer Dashboard to get the application ID since it’s not returned with any of the APIs. :slightly_smiling_face:

I was finally able to get the application ID. sq0idp-dixAN53RxQunfJnYYm_mPQ
I just ran it 10-13-2023 @ 8:20am EST.

There are two API calls to SearchCatalog today and neither requests have include_deleted_objects in the requests.
Request one:

{
  "object_types": [
    "ITEM"
  ],
  "query": {
    "prefix_query": {
      "attribute_name": "name",
      "attribute_prefix": "DAY4NV004600"
    }
  },
  "limit": 100
}

Request two:

{
  "object_types": [
    "ITEM"
  ],
  "query": {
    "prefix_query": {
      "attribute_name": "name",
      "attribute_prefix": "DAY4NV004500"
    }
  },
  "limit": 100
}


:slightly_smiling_face: