Get Resources

getResources is used to load up to 5 resources.

Note: resources.getResources(...) was introduced in v1.0.0-alpha.3. In v1.0.0-alpha.2 and older of the SDK this was resource.getResource(...) which lined up with the deprecated resource API.

Usage

getResources takes in the following object which can contain up to 5 keys (each representing a resource):

interface ResourceRequest {
    [key: string]: ResourceInput;
}
  • key is the key of the resource that will be returned.
  • ResourceInput can be an object representing any available resource request. For more details on the filters see the resources documentation.
      type ResourceInput =
          CartResourceInput |
          CategoryResourceInput |
          CategoryHierarchyResourceInput |
          CategoryListResourceInput |
          CategoryOptionsResourceInput |
          CustomerAccountResourceInput |
          DiscountListResourceInput |
          ItemResourceInput |
          ItemListResourceInput |
          LocationResourceInput |
          LocationListResourceInput |
          ScheduleDaysResourceInput |
          ScheduleTimesResourceInput;
    
      interface BaseListResourceInput {
          pagination?: {
              page_size?: number;
              page_query_param?: string;
          };
          sort?: {
              by?: string;
              order?: string;
          };
      }
    
      interface CartResourceInput {
          type: 'cart';
      }
      interface CategoryResourceInput {
          type: 'category';
          filters: {
              id: string;
              location_id?: string;
              status?: Array<string>;
              availability?: {
                  by: string;
                  time: {
                      from?: string;
                  };
              };
          };
      }
      interface CategoryHierarchyResourceInput {
          type: 'category-hierarchy';
          filters?: {
              parent?: string;
              location_id?: string;
          };
      }
      interface CategoryListResourceInput extends BaseListResourceInput {
          type: 'category-list';
          filters?: {
              ids?: Array<string>;
              location_id?: string;
              status?: Array<string>;
              search?: string;
              availability?: {
                  by: string;
                  time: {
                      from?: string;
                  };
              };
          };
      }
      interface CategoryOptionsResourceInput {
          type: 'category-options';
          filters: {
              category_id: string;
          };
      }
      interface CustomerAccountResourceInput {
          type: 'customer-account';
      }
      interface DiscountListResourceInput extends BaseListResourceInput {
          type: 'discount-list';
      }
      interface ItemResourceInput {
          type: 'item';
          filters: {
              id: string;
              location_id?: string;
              square_online_id?: boolean;
          };
      }
      interface ItemListResourceInput extends BaseListResourceInput {
          type: 'item-list';
          filters?: {
              ids?: Array<string>;
              location_id?: string;
              status?: Array<string>;
              category_id?: string;
              category_ids?: Array<string>;
              price_min?: number;
              price_max?: number;
              search?: string;
              fulfillments?: Array<string>;
              square_online_id?: boolean;
              similar_item_ids?: Array<string>;
              option_choices?: Array<string>;
              has_discounts?: boolean;
          };
      }
      interface LocationResourceInput {
          type: 'location';
          filters: {
              id: string;
              square_online_id?: boolean;
          };
      }
      interface LocationListResourceInput extends BaseListResourceInput {
          type: 'location-list';
          filters?: {
              ids?: Array<string>;
              square_online_id?: boolean;
              fulfillments?: Array<string>;
          };
      }
      interface ScheduleDaysResourceInput {
          type: 'schedule-days';
          filters?: {
              location_id?: string;
              square_online_id?: boolean;
              day?: string;
              range?: number;
          };
      }
      interface ScheduleTimesResourceInput {
          type: 'schedule-times';
          filters: {
              location_id?: string;
              square_online_id?: boolean;
              fulfillment?: boolean;
              day?: string;
              interval?: string;
          };
      }
    

Example

const resourceRequest = {
    'categoryListResource': {
        type: 'category-list'
    },
    'categoryOptionsResource': {
        type: 'category-options',
        filters: {
            category_id: '2'
        }
    },
    'itemListResource': {
        type: 'item-list',
        filters: {
            'option_choices': [ "11ee258c913644169c41a2491ad79fa8" ],
            'square_online_id': true
        }
    },
    'cartResource': {
        type: 'cart',
    },
    'itemResource': {
        type: 'item',
        filters: {
            'id': "47HCEE6ZQUFFY3Y7X52CRVCO"
        }
    }
};
try {
    const resources = await sdk.resources.getResource(resourceRequest);
} catch (error) {
    // Handle errors
}

Return Value

On success the following object is returned.

interface ResourceResponse {
    [key: string]: any;
}
  • key is the same key we used in the request object, and the value is the resource being returned.

An example simplified return value from the example above. See the resources documentation for what the resource objects would look like.

{
    cartResource: {
        errors: [],
        data: {
            // cart resource
        }
    },
    categoryListResource: {
        errors: [],
        data: [
            {
                // category resource
            },
            {
                // category resource
            }
        ]
    },
    categoryOptionsResource: {
        errors: [],
        data: [
            {
                // category options resource
            }
        ]
    },
    itemListResource:  {
        errors: [],
        data: [
            {
                // item resource
            },
            {
                // item resource
            },
            {
                // item resource
            }
        ]
    },
    itemResource: {
        errors: [],
        data: {
            // item resource
        }
    }
}

Error Handling

The SDK does no special error handling for this POST request. On a failed fetch it will just throw the generic Error.