Edits history of script submission #19991 for ' Add Connection from Source to Warehouse (segment)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Segment = {
      token: string;
      baseUrl: string;
    };
    /**
     * Add Connection from Source to Warehouse
     * Connects a Source to a Warehouse.
    
    
    
    • When called, this endpoint may generate the `Storage Destination Modified` event in the audit trail.
          
     */
    export async function main(
      auth: Segment,
      warehouseId: string,
      sourceId: string,
    ) {
      const url = new URL(
        `${auth.baseUrl}/warehouses/${warehouseId}/connected-sources/${sourceId}`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago