Edits history of script submission #20820 for ' UpdateJob (square)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Square = {
      token: string;
    };
    /**
     * UpdateJob
     * Updates the title or tip eligibility of a job. Changes to the title propagate to all
    `JobAssignment`, `Shift`, and `TeamMemberWage` objects that reference the job ID. Changes to
    tip eligibility propagate to all `TeamMemberWage` objects that reference the job ID.
     */
    export async function main(
      auth: Square,
      job_id: string,
      body: {
        job: {
          id?: string;
          title?: string;
          is_tip_eligible?: false | true;
          created_at?: string;
          updated_at?: string;
          version?: number;
        };
      },
    ) {
      const url = new URL(
        `https://connect.squareup.com/v2/team-members/jobs/${job_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