Edits history of script submission #21020 for ' Update a Location (tomorrow)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Tomorrow = {
      apiKey: string;
    };
    /**
     * Update a Location
     *
     */
    export async function main(
      auth: Tomorrow,
      locationId: string,
      Accept_Encoding: string,
      body: { name?: string; direction?: number },
    ) {
      const url = new URL(`https://api.tomorrow.io/v4/locations/${locationId}`);
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Accept-Encoding": Accept_Encoding,
          "Content-Type": "application/json",
          ApiKey: 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