Node.js searchCatalogItems API - G

const { ApiError, Client, Environment } = require(‘square’);

const SQ_CAT_FIREWORKS = “52MKWNKAMWTQZQZVUYII4SDD”;

// Configure Square default client
const squareClient = new Client({
environment: environment,
});

// Configure Square Catalog API instance
const catalogInstance = squareClient.catalogApi;

  const searchCatalogItemsAPIdata = {
      category_ids: [ SQ_CAT_FIREWORKS ],
      limit: 100,
      cursor: ""
  };

  // post body data 
  // request options
  const options = {
      method: 'POST',
      body: JSON.stringify(searchCatalogItemsAPIdata),
      headers: {
      'Square-Version': '2021-06-16',
      'Authorization': 'Bearer ' + accessToken,
      'Content-Type': 'application/json'
      }
  };

  try {
    console.log(options);
      const response = catalogInstance.searchCatalogItems(options);
      console.log(response.result);
  } catch(error) {
      console.log(error);
  }

The full title read “Going in circles”… help!

I’ve managed to fight my way past oAuth2. I’m authenticated, and I have a valid accessToken in my grubby little paws. My goal, is to create some basic inventory reports. For all items in the specified category, I need to list them, with the IN_STOCK values at a subset of our locations. I’ll need to do more… but this is the hill I’m dying on right now. I assume two calls, one to get the list of items in the catalog, and then another to get the item inventory data.

Problem #1: I’m now attempting to search for all items in the FIREWORKS category. Based on the above code (or about 17 permutations of it over the last 5 hours), I’m getting a http 401 error, which clearly says to me that I’m not conveying the accessToken (and perhaps other header/body info) correctly to the Square API. I can’t find a specific example showing that part of the process. Can someone point me in the proper direction or provide a snippet that would show me the error of my ways? I’m guessing that once I can make a single API work, I can duplicate it in terms of process, and then just focus on the vagaries of the API itself.

Problem #2: Anticipated really, I believe I’m going to encounter cursor management within these calls to get the quantity of data back that will come. Having never done it before, anyone have a working snippet around using the Square APIs with cursor management? I imagine it is basically going to be initializing a cursor variable to an empty string, a do/while loop for the API call, terminating when the cursor is again empty? Again, if someone has a working snippet, I’d be grateful.

Problem #3: Is there an API flow that would reasonably easy allow me to take some form fields and update the inventory (received stock and/or recounted stock) for a subset of locations? It sounds like I’m going to need to make a series of smaller calls, but again, I’m can’t be the only one doing this - so I imagine I’m missing something major. Related, we have a need to transfer inventory between locations as a common occurrence. There is no inventory transfer API that I can see (and no ‘TRANSFER’ reason code to use to mark the activity), I presume this is going to be a two part operation - a “RECOUNT” subtraction from the donor location and a “STOCK_RECEIVED” for the recipient location? It seems really strange there isn’t a stock adjustment reason of ‘TRANSFER’.

Problem #4: It’s late, I’ve got a lot to do, and there isn’t enough caffeine in my immediate vicinity… lol

Thanks in advance to anyone who gives this a read, and bonus gratitude points for anyone who can shed some fast light on this stuff. I’ve banging my head here, and not in a good way…