Edits history of script submission #16195 for ' Update a change request (gitbook)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gitbook = {
      token: string;
    };
    /**
     * Update a change request
     *
     */
    export async function main(
      auth: Gitbook,
      spaceId: string,
      changeRequestId: string,
      body: { subject?: string; status?: "draft" | "open" | "archived" },
    ) {
      const url = new URL(
        `https://api.gitbook.com/v1/spaces/${spaceId}/change-requests/${changeRequestId}`,
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        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