Edits history of script submission #20607 for ' CreateBreakType (square)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Square = {
      token: string;
    };
    /**
     * CreateBreakType
     * Creates a new `BreakType`.
    
    A `BreakType` is a template for creating `Break` objects.
    You must provide the following values in your request to this
    endpoint:
    
    - `location_id`
    - `break_name`
    - `expected_duration`
    - `is_paid`
    
    You can only have three `BreakType` instances per location. If you attempt to add a fourth
    `BreakType` for a location, an `INVALID_REQUEST_ERROR` "Exceeded limit of 3 breaks per location."
    is returned.
     */
    export async function main(
      auth: Square,
      body: {
        idempotency_key?: string;
        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`);
    
      const response = await fetch(url, {
        method: "POST",
        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