sites.ts•1.67 kB
import fetch from 'node-fetch';
import { ApiMethodInfo, ApiParameter } from '../api-types.js';
import FormData from 'form-data';
import { baseUrl, apiVersion, getRequestHeaders, handleResponse } from '../config.js';
import * as fs from 'fs';
import * as path from 'path';
import { typeMap } from '../utils/type-map.js';
/**
* Method information for each API endpoint
*/
export const SitesMethods: { [key: string]: ApiMethodInfo } = {
list: {
description: "Sites are listed in descending order by the `created_at` date.\n\n\n__Note:__ Square Online APIs are publicly available as part of an early access program. For more information, see [Early access program for Square Online APIs](https://developer.squareup.com/docs/online-api#early-access-program-for-square-online-apis).",
method: "get",
path: "/v2/sites",
pathParams: [],
queryParams: [],
requestType: "ListSitesRequest",
isMultipart: false,
originalName: "ListSites",
isWrite: false
} as ApiMethodInfo
};
/**
* Handlers for each API endpoint
*/
export const SitesHandlers = {
list: async (accessToken: string, args: Record<string, unknown>) => {
const methodInfo = SitesMethods.list;
// Simple endpoint with no path or query parameters
const url = methodInfo.path;
// Make regular JSON request
const response = await fetch(`${baseUrl}${url}`, {
method: methodInfo.method.toUpperCase(),
headers: getRequestHeaders(accessToken),
...(Object.keys(args).length > 0 && ['post', 'put', 'patch'].includes(methodInfo.method.toLowerCase()) && { body: JSON.stringify(args) })
});
return await handleResponse(response)
}
};