Edits history of script submission #3133 for ' Update a Custom Field definition (trello)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Trello = {
      key: string;
      token: string;
    };
    /**
     * Update a Custom Field definition
     * Update a Custom Field definition.
     */
    export async function main(
      auth: Trello,
      id: string,
      body: {
        name?: string;
        pos?: ("top" | "bottom") | number;
        "display/cardFront"?: boolean;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(`https://api.trello.com/1/customFields/${id}`);
      for (const [k, v] of [
        ["key", auth.key],
        ["token", auth.token],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: undefined,
        },
        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 398 days ago

  • nativets
    type Trello = {
      key: string;
      token: string;
    };
    /**
     * Update a Custom Field definition
     * Update a Custom Field definition.
     */
    export async function main(
      auth: Trello,
      id: string,
      body: {
        name?: string;
        pos?: ("top" | "bottom") | number;
        "display/cardFront"?: boolean;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(`https://api.trello.com/1/customFields/${id}`);
      for (const [k, v] of [
        ["key", auth.key],
        ["token", auth.token],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: undefined,
        },
        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 953 days ago