Curl upsert call succeeds, identical Java API call throws `ExecutionException`

Hello there Square folks,

I am facing a weird problem with the Java API. Namely, if I go to the API explorer and build up my request, the resulting curl payload:

curl https://connect.squareupsandbox.com/v2/catalog/object \
  -X POST \
  -H 'Square-Version: 2020-11-18' \
  -H 'Authorization: Bearer MY_SANDBOX_ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "idempotency_key": "77e59159-9c23-4b20-b4b4-5bfbdef7482d",
    "object": {
      "id": "#RANDOM_ID",
      "type": "ITEM",
      "item_data": {
        "abbreviation": "RAM",
        "description": "Will challenge his father for the throne",
        "label_color": "7FAAD4",
        "name": "RAMSES V",
        "variations": [
          {
            "id": "#RANDOM_ID_VAR",
            "type": "ITEM_VARIATION",
            "item_variation_data": {
              "item_id": "#RANDOM_ID",
              "name": "RAMSES V_DEFAULT_VARIATION",
              "price_money": {
                "amount": 10000,
                "currency": "USD"
              },
              "pricing_type": "FIXED_PRICING",
              "sku": "RANDOM_SKU",
              "upc": "RANDOM_UPC"
            }
          }
        ]
      }
    }
  }

works just fine. However, when using the Java API, I have prepared an identical UpsertCatalogObjectRequest instance which I am sending by calling upsertCatalogObjectAsync and it throws an ExecutionException, with an embedded APIException instance whose message is the rather uninformative com.squareup.square.exceptions.ApiException: HTTP Response Not OK.

If you check the screenshots below from my IDE, which are taken right before I make that call, I believe that the contents of the UpserCatalogObjectRequest I am forming are exactly the same as those in the curl request above.

Here you can see the entire UpsertCatalogObjectRequest instance:

!

Here you can see the CatalogItem that is embedded within the CatalogObject inside the UpsertCatalogObjectRequest:

!

And, finally, here you can see the CatalogItemVariation field that is embedded within the CatalogItem:

(Note: the priceMoney field is not showing under the CatalogItemVariation information, but I can assure you that it has the exact same values as the curl payload above).

What am I doing wrong here? I should also say that at some random point this morning, the same Java upsert call actually went through just fine, but every other time I’ve tried it today I get the same exception, with the curl working just fine.

If it is in any way important, the app that I am testing is called caliskunk, it has Sandbox application id: sandbox-sq0idb-4jMU5yV5e77-2cqM9IxHEA and the sandbox account is Caliskunk - Sandbox. Thank you for your help with all of my concerns, it really means a lot.

Looking up the logs for your application I found two different catalog related errors:

response=<errors:<category:INVALID_REQUEST_ERROR code:INVALID_ENUM_VALUE detail:"`` is not a valid enum value for `object.item_data.product_type`." field:"object.item_data.product_type" > >

and

response=<errors:<category:INVALID_REQUEST_ERROR code:INVALID_VALUE detail:"Item Variation with id #RANDOM_ID_VAR has FIXED_PRICING pricing_type but no price_money" > >

I do see a successful UpsertCatalogObject request about 20 minutes after the last error, but that may have been your API Explorer testing.

Unfortunately both of those were done with the API explorer, including the wrong call. I am guessing that the Java calls do not even appear on Square’s servers :frowning: I just made one (6:28PM my time), under the same credentials; is there any way you can tell me if the logs betray that it was receved but rejected?

Yeah the last time I see UpsertCatalogObject called with that application id was at 6:47 am PST. Are you using a different application id now by chance?

Unfortunately not, I am using the same application, with square ID sandbox-sq0idb-4jMU5yV5e77-2cqM9IxHEA. Same object, same sandbox access token…

Local problem! I am fetching my access token from an environment var called SQUARE_SANDBOX_ACCESS_TOKEN and instead of just my_token as its value, I had accidentally put in the entire string SQUARE_SANDBOX_ACCESS_TOKEN=my_token… No problems on Square’s end.

1 Like

Ah, glad you figured it out! Thanks for sharing :slight_smile: