Edits history of script submission #16437 for ' Update project time (holded)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Holded = {
      apiKey: string;
    };
    /**
     * Update project time
     * Update a specific time tracking.
    
    Only the params included in the operation will update the time tracking.
     */
    export async function main(
      auth: Holded,
      projectId: string,
      timeTrackingId: string,
      body: {
        duration: number;
        desc?: string;
        costHour: number;
        userId?: string;
        taskId?: string;
      },
    ) {
      const url = new URL(
        `https://api.holded.com/api/projects/v1/projects/${projectId}/times/${timeTrackingId}`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          key: auth.apiKey,
        },
        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