Edits history of script submission #375 for ' Get all active stripe products from your account (stripe)'

  • deno
    type Stripe = {
      token: string;
    };
    export async function main(stripeAuth: Stripe) {
      let has_more = true;
      let starting_after = "";
      const products = [];
    
      // if you have a lot of products (> 200), you may want to consider to throttle.
      while (has_more) {
        const res = await getStripeProductsIds(stripeAuth.token, starting_after);
        has_more = res.has_more;
        starting_after = res.data[res.data.length - 1].id;
        products.push(...res.data);
      }
    
      return products;
    }
    
    async function getStripeProductsIds(stripeKey: string, starting_after = "") {
      let url = "https://api.stripe.com/v1/products?limit=10";
      if (starting_after) {
        url += `&starting_after=${starting_after}`;
      }
      const products = await fetch(url, {
        headers: {
          Authorization: `Bearer ${stripeKey}`,
        },
      }).then((res) => res.json());
    
      return products;
    }
    

    Submitted by hugo697 399 days ago

  • deno
    type Stripe = {
      token: string;
    };
    export async function main(stripeAuth: Stripe) {
      let has_more = true;
      let starting_after = "";
      const products = [];
    
      // if you have a lot of products (> 200), you may want to consider to throttle.
      while (has_more) {
        const res = await getStripeProductsIds(stripeAuth.token, starting_after);
        has_more = res.has_more;
        starting_after = res.data[res.data.length - 1].id;
        products.push(...res.data);
      }
    
      return products;
    }
    
    async function getStripeProductsIds(stripeKey: string, starting_after = "") {
      let url = "https://api.stripe.com/v1/products?limit=10";
      if (starting_after) {
        url += `&starting_after=${starting_after}`;
      }
      const products = await fetch(url, {
        headers: {
          Authorization: `Bearer ${stripeKey}`,
        },
      }).then((res) => res.json());
    
      return products;
    }
    

    Submitted by admin 1031 days ago

  • deno
    
    type Stripe = {
      token: string;
    };
    export async function main(stripeAuth: Stripe) {
      let has_more = true;
      let starting_after = "";
      const products = [];
    
      // if you have a lot of products (> 200), you may want to consider to throttle.
      while (has_more) {
        const res = await getStripeProductsIds(
          stripeAuth.token,
          starting_after,
        );
        has_more = res.has_more;
        starting_after = res.data[res.data.length - 1].id;
        products.push(...res.data);
      }
    
      return products;
    }
    
    async function getStripeProductsIds(
      stripeKey: string,
      starting_after = "",
    ) {
      let url = "https://api.stripe.com/v1/products?limit=10";
      if (starting_after) {
        url += `&starting_after=${starting_after}`;
      }
      const products = await fetch(url, {
        headers: {
          "Authorization": `Bearer ${stripeKey}`,
        },
      }).then((res) => res.json());
    
      return products;
    }
    

    Submitted by admin 1034 days ago

  • deno
    import type { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    
    export async function main(stripeAuth: Resource<"stripe">) {
      let has_more = true;
      let starting_after = "";
      const products = [];
    
      // if you have a lot of products (> 200), you may want to consider to throttle.
      while (has_more) {
        const res = await getStripeProductsIds(
          stripeAuth.token,
          starting_after,
        );
        has_more = res.has_more;
        starting_after = res.data[res.data.length - 1].id;
        products.push(...res.data);
      }
    
      return products;
    }
    
    async function getStripeProductsIds(
      stripeKey: string,
      starting_after = "",
    ) {
      let url = "https://api.stripe.com/v1/products?limit=10";
      if (starting_after) {
        url += `&starting_after=${starting_after}`;
      }
      const products = await fetch(url, {
        headers: {
          "Authorization": `Bearer ${stripeKey}`,
        },
      }).then((res) => res.json());
    
      return products;
    }
    

    Submitted by sindre svendby964 1111 days ago