Bear with me here!
Im trying to build a site that pulls every item from my catalog using listCatalog and maps it out. I got the mapping of the catalog down (its super sloppy dont judge), but apparently the list catalog API doesnt carry the image URL! The only solution I can think of is to grab my image ID from my listCatalog instance, and run it through the RetrieveCatalogObject instance, but Im not terribly sure about how to logically do that. or if I even have to. to be honest.
My question for y’all is twofold:
-
Does the list catalog carry the image URL? It seems counter-intuitive to me that it wouldnt. I mean, its a part of the catalog on upload after all lol
If anyone feels like helping, heres my awful attempt at this
Im using NextJS
**pages/menu/index.tsx
import Image from 'next/image';
import React from 'react'
import { Client, Environment } from 'square'
(BigInt.prototype as any).toJSON = function() { return this.toString(); }
const Menu = ({results, data}) => {
console.log(data);
return (
<div>
<h1>Menu</h1>
{ results && results.objects.map(items => (
<>
<h2>{ items.itemData.name }</h2>
<h3> { items.itemData.description} </h3>
<h3> { items.id } </h3>
{ data && data.objects.map(bro => (
<>
<h2>{bro.id}</h2>
</>
))}
{items.itemData.variations.map(variation => (
// this is my current solution for displaying price variations. its not elegant, but it gets the job done. God speed when it comes to importing the image
<>
<p>{variation.itemVariationData.name}:</p>
<p> $ {`${(Math.round(variation.itemVariationData.priceMoney.amount) / 100).toFixed(2) }`}
</p>
</>
))}
</>
))}
</div>
)
}
export default Menu
export async function getServerSideProps(){
console.log('hello world! kinda..');
const config = ({
accessToken: process.env.SQUARE_ACCESS_TOKEN,
environment: Environment.Sandbox,
});
const { catalogApi } = new Client(config);
const {result } = await catalogApi.listCatalog(undefined, 'ITEM');
// const data = await res.json();
const oof = await catalogApi.searchCatalogObjects({
objectTypes: [
'IMAGE'
],
includeDeletedObjects: false,
includeRelatedObjects: true
});
console.log("image JSON is", oof.body);
return {
props: {
data: JSON.parse(oof.body.toString()),
results: JSON.parse(JSON.stringify(result))
}
}
}