BatchUpsertCatalogObjects - VERSION_MISMATCH

Hi, BatchUpsert is working great when I insert objects, when their id is #someid. I’ve record square id and version in my database, and when I tried to batchupsert the catalog I received the VERSION_MISMATCH error and no indication on which Object Id is causing the problem.

Is there a way to get that information?

:wave: Unfortunately the list of objects that have the version mismatch isn’t available to be returned in the error. We’re constantly working to improve our features based on feedback like this, so I’ll be sure to share your request to the API product team. :slightly_smiling_face:

@Bryan-Square, May I pass you the complete object for you to analyze the case and tell me what I’m doing wrong?

The version error is pretty self explanatory. Often time the object in your database can differ from the actual object depending on where it’s been updated. This is where Optimistic Concurrency comes into play. We recommend that when you encounter this error that you have a function that BatchRetrievesCatalogObjects for all the items in your request and parses the results for differences to identify what’s changed. :slightly_smiling_face:

Thanks you very much Bryan, but I’ve already done that. I’ve retrieved the full catalog from square and compared all the object versions with the ones in my database. There weren’t any differences. That’s why my insistence. But, it’s ok, I’m new with this API, so I asume that there are things that I still misunderstand.

That is odd. Was there any differences with the versions of the item_variations?

Hi Bryan, no, there wasn’t any. Look, here’s my endpoint to control differences between square and my database. It threw no errors. Of course I’ve forced a couple of errors just to check if it was working fine.
Again, I can delete the entire catalog using BatchDeleteCatalogObjectsAsync, also I can upload an entire catalog using BatchUpsertCatalogObjectsAsync, and all the objects (item and item_variation) referenced by #ids. But when I try to run BatchUpsertCatalogObjectsAsync retrieving the square codes and versions from my database the answer is always VERSION_MISMATCH. Do you want me to attach a full BatchCatalog object?.

public async Task<IActionResult> ControlCatalog([FromHeader(Name = "X-Auth-Token")] string authtoken, string id)
{
    bool goOn = true;
    string cursor = "";
    var sigConnect = Globals.GetClient(id, authtoken);
    var howmany = 0;
    var sigmatype = "";
    var errores = new List<object>();
    long versaux = 0;
    JObject sigmavers;
    try
    {
        while (goOn)
        {
            var result = await sqclient.CatalogApi.ListCatalogAsync(types: "item,item_variation", cursor: (string.IsNullOrEmpty(cursor) ? null : cursor));
            if (result.Objects != null)
            {
                howmany += result.Objects.Count();
                goOn = result.Cursor == null ? false : true;
                cursor = result.Cursor ?? "";

                foreach (var item in result.Objects)
                {
                    sigmatype = item.Type == "ITEM_VARIATION" ? "art_arch" : "art_rubr";

                    sigmavers = await sigConnect.ValuesAsync(
                                            sql: "select fcodigo, fdatadi->>'square_version' as version from " + sigmatype + " where fdatadi->>'square_code' = :param",
                                            parameters: new dynamic[] { item.Id });

                    versaux = sigmavers["version"]!.Count() != 0 ? Convert.ToInt64(sigmavers["version"]) : 0;

                    if (versaux != item.Version)
                    {
                        errores.Add(new { tipo = sigmatype, codigo = sigmavers["fcodigo"], square_code = item.Id, sigmaversion = sigmavers["version"], square_version = item.Version });
                    }
                }
            }
            else
            {
                goOn = false;
            }
        }
    }
    catch (ApiException e)
    {
        return Problem(title: e.Message + " - " + e.Errors[0].Code,
                        detail: e.Errors[0].Detail,
                        statusCode: e.ResponseCode);
    }

    return Ok("Records in Square: " + howmany + "\n" + JsonSerializer.Serialize(errores));
}

Yeah, if you could provide the request we can take a look.

Well Bryan, I gave up!. I don´t store the versions anymore, I just grab them from square with

sqclient.CatalogApi.RetrieveCatalogObjectAsync(objectId: itemid))

and then the BatchUpsertCatalogObjectsAsync works perfect!. Thank you for your patience!