Edits history of script submission #20812 for ' UpdateBreakType (square)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Square = {
      token: string;
    };
    /**
     * UpdateBreakType
     * Updates an existing `BreakType`.
     */
    export async function main(
      auth: Square,
      id: string,
      body: {
        break_type: {
          id?: string;
          location_id: string;
          break_name: string;
          expected_duration: string;
          is_paid: false | true;
          version?: number;
          created_at?: string;
          updated_at?: string;
        };
      },
    ) {
      const url = new URL(
        `https://connect.squareup.com/v2/labor/break-types/${id}`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago