Payment's order_id returns an resource not found when requesting the order object. (Square 2022-06-16)

I am scraping the list of payments in order to build a database for customers. This database needs to include what items were sold, taxes, etc. So far the approach works except when the payment is for an order which only contains a gift card purchase, custom amount, and custom amount + tip. At which point the order object pointed to by the order_id returns an error of resource not found.

I don’t know if there is some other way to recover this information other than potentially parsing the receipt given by the receipt url.

I am pulling this information using the Web based API.

What’s the order_id your getting this error with? :slightly_smiling_face:

I have 11 over three days of activities. I’ve checked the receipt of the first 3 which are custom amount, gift card purchase, and custom amount + tip. The ids are below:

c796IkmCCIysLU0fVvNOU1ieV
uY5T0AWQKU1SVCipYLqX4sxeV
mwbrbCNXrWhCP38nttbrxMseV
QD8ULqmQN3I2xOTxH9og7voeV
u6OtwObusTSAcqHBWH8nlEAfV
shu7uVFjZXpctvrM7vtuoIreV
sz71utAKtymAYz9ibqHSKOgeV
w3ANTU9CMEalKaMiRraMM28eV
WMZNrDfIEn5bbZeT9qew3B0eV
o1Rr43Unx52sEYKZ7bG0DlneV
05AJBIhQFgQbf9DUaM3JtR1eV

I went through the list you provided and all of these order returned a response for me:

05AJBIhQFgQbf9DUaM3JtR1eV
c796IkmCCIysLU0fVvNOU1ieV
uY5T0AWQKU1SVCipYLqX4sxeV
mwbrbCNXrWhCP38nttbrxMseV
QD8ULqmQN3I2xOTxH9og7voeV

These orders returned no response cause they’re voided or declined orders:

u6OtwObusTSAcqHBWH8nlEAfV
shu7uVFjZXpctvrM7vtuoIreV
sz71utAKtymAYz9ibqHSKOgeV
w3ANTU9CMEalKaMiRraMM28eV
WMZNrDfIEn5bbZeT9qew3B0eV
o1Rr43Unx52sEYKZ7bG0DlneV

If you try the top group again do the orders come in? Also are you checking the status of the payment prior to calling the Orders API so you don’t call CANCELED, or FAILED payment order since they’re not returned? :slightly_smiling_face:

Looking back over those orders I still don’t get the correct response, I get the same response for each and it is:

{
  "errors": [
    {
      "category": "INVALID_REQUEST_ERROR",
      "code": "NOT_FOUND",
      "detail": "Resource not found."
    }
  ]
}

Code to reproduce (using simple Python for testing this stuff because familiarity/speed but same errors in Scala):

import requests
url = "https://connect.squareup.com/v2/"+parm
header = {"Authorization":"Bearer "+token,
          "Square-Version" : "2022-06-16" }
ids = [
        "05AJBIhQFgQbf9DUaM3JtR1eV",
        "c796IkmCCIysLU0fVvNOU1ieV",
        "uY5T0AWQKU1SVCipYLqX4sxeV",
        "mwbrbCNXrWhCP38nttbrxMseV",
        "QD8ULqmQN3I2xOTxH9og7voeV",
        ]
for i in ids:
    a = requests.get(url+"/"+i,headers=header,stream=True).text
    print(a)

For some reason that didn’t cross my mind, though I didn’t delve into the other orders, so thanks for the suggestion and I will implement that.

Are you passing in the right location_id parameter? :slightly_smiling_face:

Assuming I am reading the API correctly, there is no need to pass a location_id.

Though upon your above statement I did just investigate pure curl based interaction and that does work whereas the requests library from Python and scalaj-http return the error above.

curl https://connect.squareup.com/v2/orders/c796IkmCCIysLU0fVvNOU1ieV \
  -H 'Square-Version: 2022-06-16' \
  -H 'Authorization: Bearer $ACCESS_TOKEN' \

I think the solution you gave in telling me to filter CANCELLED/FAILED payments combined with my recent realization that I just needed to make my connection times longer (though I still find it interesting that it is a few consistent seemingly related cases upon which it fails) to have been the solution. Which I guess I should have played with connection times to begin with but the consistency of cases made me think it was something else.

Thanks for the help and back and forth.

Glad to hear you figured it all out. :slightly_smiling_face: