Get Customer Subscriptions using Stripe API

import os
from flask import Flask, jsonify, render_template_string

# Set the Stripe API key from environment variables
stripe_api_key = os.environ.get('STRIPE_API_KEY')
if not stripe_api_key:
    raise ValueError("The STRIPE_API_KEY environment variable is not set.")

import stripe
stripe.api_key = stripe_api_key

app = Flask(__name__)

# HTML content for listing customer subscriptions
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Stripe Customer Subscriptions</title>

About this template

This app uses the Stripe API to get all active customer subscriptions. It includes a Flask web service with an endpoint for this purpose. The backend makes an API call to get all active customer subscriptions using the Stripe API. The app displays the list. This app can be customized to also get Stripe subscriptions by customer id.

Introduction to the Stripe Customer Subscriptions Template

Welcome to the Stripe Customer Subscriptions template! This template is designed to help you create an application that uses the Stripe API to retrieve and display a list of active customer subscriptions. It's built with Flask, a lightweight web framework for Python, and is perfect for builders looking to integrate Stripe subscription data into their applications without deep technical knowledge.

Getting Started

To begin using this template, simply click on "Start with this Template" on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code manually.

Initial Setup

Before you can test and use the application, you'll need to set up an environment secret within the Lazy Builder:

  • STRIP_API_KEY: This is your Stripe secret key, which allows your application to communicate with Stripe's API securely. You can find your API keys in the Stripe Dashboard under Developers > API keys. Make sure to use the secret key, not the publishable one.

To add this environment secret:

  1. Go to the Environment Secrets tab within the Lazy Builder.
  2. Click on "Add Secret".
  3. Enter "STRIPE_API_KEY" as the name and paste your Stripe secret key as the value.
  4. Save the secret.

With the environment secret in place, your application will be able to authenticate with Stripe and retrieve subscription data.


Once you have set up the environment secret, you can test the application by pressing the "Test" button. This will deploy your app and launch the Lazy CLI. There is no need for additional user input through the CLI for this template, as the required information is provided by the environment secret you set up.

Using the App

After pressing the "Test" button, Lazy will provide you with a dedicated server link. Use this link to access the web interface of your application. The main page will display a list of Stripe customer subscriptions. The app fetches this data from Stripe and updates the display automatically.

If you need to customize the application further, such as filtering subscriptions by customer ID, you can modify the code within the Lazy Builder interface to suit your specific requirements.

Integrating the App

If you wish to integrate this application into an existing service or frontend, you can use the server link provided by Lazy as the endpoint for your API calls. For example, if you have a customer management dashboard, you can add a section that displays subscription information by fetching data from your Flask application's '/list_subscriptions' endpoint.

Here's a sample request you might use in your external service to get the subscription data:

  .then(response => response.json())
  .then(subscriptions => {
    // Process and display the subscriptions data
  .catch(error => console.error('Error:', error));

Replace 'YOUR_LAZY_SERVER_LINK' with the actual server link provided by Lazy. The response will be a JSON array containing the subscription details, which you can then use within your service.

By following these steps, you should now have a fully functional application that lists Stripe customer subscriptions. You can further customize and integrate this app as needed for your specific use case.

Last published
June 15, 2024

More templates like this

PDF Data Extraction and Excel Transfer

An app for extracting name, phone number, and email data from PDF files and transferring it to Excel.


FALLBACK | Flask, HTML, JS and Tailwind Based Website

This is a good starting point for styled website. It has a header, footer. Has Tailwind and Flowbite loaded so you can build nice looking pages from here.


FALLBACK LATEST 1 THEME | Flask, HTML, JS and Tailwind Based Website

This is a good starting point for styled website. It has a header, footer. Has Tailwind and Flowbite loaded so you can build nice looking pages from here.

Get Customer Subscriptions using Stripe API