← Fauna + ReCharge integrations

Create Subscription with ReCharge API on New or Removed Documents in a Collection from Fauna API

Pipedream makes it easy to connect APIs for ReCharge, Fauna and 2,500+ other apps remarkably fast.

Trigger workflow on
New or Removed Documents in a Collection from the Fauna API
Next, do this
Create Subscription with the ReCharge API
No credit card required
Intro to Pipedream
Watch us build a workflow
Watch us build a workflow
8 min
Watch now ➜

Trusted by 1,000,000+ developers from startups to Fortune 500 companies

Adyen logo
Appcues logo
Bandwidth logo
Checkr logo
ChartMogul logo
Dataminr logo
Gopuff logo
Gorgias logo
LinkedIn logo
Logitech logo
Replicated logo
Rudderstack logo
SAS logo
Scale AI logo
Webflow logo
Warner Bros. logo
Adyen logo
Appcues logo
Bandwidth logo
Checkr logo
ChartMogul logo
Dataminr logo
Gopuff logo
Gorgias logo
LinkedIn logo
Logitech logo
Replicated logo
Rudderstack logo
SAS logo
Scale AI logo
Webflow logo
Warner Bros. logo

Developers Pipedream

Getting Started

This integration creates a workflow with a Fauna trigger and ReCharge action. When you configure and deploy the workflow, it will run on Pipedream's servers 24x7 for free.

  1. Select this integration
  2. Configure the New or Removed Documents in a Collection trigger
    1. Configure timer
    2. Connect your Fauna account
    3. Select a Collection
    4. Optional- Configure Emit changes as a single event
  3. Configure the Create Subscription action
    1. Connect your ReCharge account
    2. Select a Address ID
    3. Configure Charge Interval Frequency
    4. Configure Next Charge Scheduled At
    5. Configure Order Interval Frequency
    6. Select a Order Interval Unit
    7. Configure Quantity
    8. Select a External Variant ID
    9. Configure Additional Options
  4. Deploy the workflow
  5. Send a test event to validate your setup
  6. Turn on the trigger

Details

This integration uses pre-built, source-available components from Pipedream's GitHub repo. These components are developed by Pipedream and the community, and verified and maintained by Pipedream.

To contribute an update to an existing component or create a new component, create a PR on GitHub. If you're new to Pipedream component development, you can start with quickstarts for trigger span and action development, and then review the component API reference.

Trigger

Description:Emit new event each time you add or remove a document from a specific collection, with the details of the document.
Version:0.0.8
Key:faunadb-changes-to-collection

Fauna Overview

Fauna API offers a powerful serverless database solution for modern applications. Its unique capabilities allow for highly scalable, secure, and flexible data management. With Pipedream, you can harness the power of Fauna to create intricate serverless workflows that react to various triggers, manage data efficiently, and connect seamlessly with other services and APIs to automate complex tasks.

Trigger Code

import fauna from "../../faunadb.app.mjs";
import _ from "lodash";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
  type: "source",
  key: "faunadb-changes-to-collection",
  name: "New or Removed Documents in a Collection",
  description: "Emit new event each time you add or remove a document from a specific collection, with the details of the document.",
  version: "0.0.8",
  dedupe: "unique", // Dedupe events based on the concatenation of event + document ref id
  props: {
    timer: {
      type: "$.interface.timer",
      default: {
        intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
      },
    },
    db: "$.service.db",
    fauna,
    collection: {
      propDefinition: [
        fauna,
        "collections",
      ],
    },
    emitEventsInBatch: {
      type: "boolean",
      label: "Emit changes as a single event",
      description:
        "If `true`, all events are emitted as an array, within a single Pipedream event. Defaults to `false`, emitting each event in Fauna as its own event in Pipedream",
      optional: true,
      default: false,
    },
  },
  async run() {
    // As soon as the script runs, mark the start time so we can fetch changes
    // since this time on the next run. Fauna expects epoch ms as its cursor.
    const ts = +new Date() * 1000;
    const cursor = this.db.get("cursor") || ts;

    const events = await this.fauna.getEventsInCollectionAfterTs(
      this.collection,
      cursor,
    );

    if (!events.length) {
      console.log(`No new events in collection ${this.collection}`);
      this.db.set("cursor", ts);
      return;
    }

    console.log(`${events.length} new events in collection ${this.collection}`);

    // Batched emits do not take advantage of the built-in deduper
    if (this.emitEventsInBatch) {
      this.$emit({
        events,
      }, {
        summary: `${events.length} new event${events.length > 1
          ? "s"
          : ""}`,
        id: cursor,
      });
    } else {
      for (const event of events) {
        this.$emit(event, {
          summary: `${event.action.toUpperCase()} - ${event.document.id}`,
          id: `${event.action}-${event.document.id}`, // dedupes events based on this ID
        });
      }
    }

    // Finally, set cursor for the next run to the max timestamp of the changed events, ensuring we
    // get all events after that on the next run. We need to add 1 since the timestamp filter in
    // Fauna is inclusive: https://docs.fauna.com/fauna/current/api/fql/functions/paginate
    const maxEventTs = _.maxBy(events, (event) => event.ts).ts + 1;

    this.db.set("cursor", maxEventTs);
  },
};

Trigger Configuration

This component may be configured based on the props defined in the component code. Pipedream automatically prompts for input values in the UI and CLI.
LabelPropTypeDescription
timer$.interface.timer
N/Adb$.service.dbThis component uses $.service.db to maintain state between executions.
FaunafaunaappThis component uses the Fauna app.
CollectioncollectionstringSelect a value from the drop down menu.
Emit changes as a single eventemitEventsInBatchboolean

If true, all events are emitted as an array, within a single Pipedream event. Defaults to false, emitting each event in Fauna as its own event in Pipedream

Trigger Authentication

Fauna uses API keys for authentication. When you connect your Fauna account, Pipedream securely stores the keys so you can easily authenticate to Fauna APIs in both code and no-code steps.

Create a key in the Security section of your FaunaDB dashboard, then enter the Secret below.

Read more about Keys and Fauna Security

About Fauna

The distributed serverless database combining the flexibility of NoSQL with the relational querying capabilities of SQL systems.

Action

Description:Creates a new subscription allowing a customer to subscribe to a product. [See the documentation](https://developer.rechargepayments.com/2021-11/subscriptions/subscriptions_create)
Version:0.0.1
Key:recharge-create-subscription

ReCharge Overview

The ReCharge API offers a programmatic entrance to the ReCharge ecosystem, a place where subscription-based e-commerce is managed with ease. Whether you're looking to synchronize customer data, manage subscriptions, or automate notifications, the API's endpoints enable you to seamlessly integrate subscription data into your business processes. With Pipedream's serverless execution model, you can craft workflows that respond to events in ReCharge, manipulate and route data, and trigger actions across your entire software stack. This opens doors to personalized customer experiences, streamlined operations, and data-driven decision-making.

Action Code

import recharge from "../../recharge.app.mjs";

export default {
  key: "recharge-create-subscription",
  name: "Create Subscription",
  description: "Creates a new subscription allowing a customer to subscribe to a product. [See the documentation](https://developer.rechargepayments.com/2021-11/subscriptions/subscriptions_create)",
  version: "0.0.1",
  type: "action",
  props: {
    recharge,
    addressId: {
      propDefinition: [
        recharge,
        "addressId",
      ],
    },
    chargeIntervalFrequency: {
      type: "integer",
      label: "Charge Interval Frequency",
      description: "The number of units, specified in `Order Interval Unit`, between each charge.",
    },
    nextChargeScheduledAt: {
      type: "string",
      label: "Next Charge Scheduled At",
      description: "This will set the first charge date of a new subscription. Can be a date string such as `2021-12-17`.",
    },
    orderIntervalFrequency: {
      type: "integer",
      label: "Order Interval Frequency",
      description: "The number of units, specified in `Order Interval Unit`, between each order.",
    },
    orderIntervalUnit: {
      type: "string",
      label: "Order Interval Unit",
      description: "The frequency unit used to determine when a subscription order is created.",
      options: [
        "day",
        "week",
        "month",
      ],
    },
    quantity: {
      type: "integer",
      label: "Quantity",
      description: "The quantity of the product.",
    },
    externalVariantId: {
      propDefinition: [
        recharge,
        "externalVariantId",
      ],
    },
    additionalOptions: {
      type: "object",
      label: "Additional Options",
      description: "Additional parameters to be passed in the request. [See the documentation](https://developer.rechargepayments.com/2021-11/subscriptions/subscriptions_create) for all available parameters.",
    },
  },
  async run({ $ }) {
    const response = await this.recharge.createSubscription({
      $,
      data: {
        address_id: this.addressId,
        charge_interval_frequency: this.chargeIntervalFrequency,
        next_charge_scheduled_at: this.nextChargeScheduledAt,
        order_interval_frequency: this.orderIntervalFrequency,
        order_interval_unit: this.orderIntervalUnit,
        quantity: this.quantity,
        external_variant_id: this.externalVariantId && {
          ecommerce: this.externalVariantId,
        },
        ...Object.fromEntries(Object.entries(this.additionalOptions).map(([
          key,
          value,
        ]) => {
          try {
            value = JSON.parse(value);
          } catch (e) {
            e; // JSON parsing is optional
          }

          return [
            key,
            value,
          ];
        })),
      },
    });

    $.export("$summary", `Successfully created a new subscription with ID ${response?.subscription?.id}`);
    return response;
  },
};

Action Configuration

This component may be configured based on the props defined in the component code. Pipedream automatically prompts for input values in the UI.

LabelPropTypeDescription
ReChargerechargeappThis component uses the ReCharge app.
Address IDaddressIdstringSelect a value from the drop down menu.
Charge Interval FrequencychargeIntervalFrequencyinteger

The number of units, specified in Order Interval Unit, between each charge.

Next Charge Scheduled AtnextChargeScheduledAtstring

This will set the first charge date of a new subscription. Can be a date string such as 2021-12-17.

Order Interval FrequencyorderIntervalFrequencyinteger

The number of units, specified in Order Interval Unit, between each order.

Order Interval UnitorderIntervalUnitstringSelect a value from the drop down menu:dayweekmonth
Quantityquantityinteger

The quantity of the product.

External Variant IDexternalVariantIdstringSelect a value from the drop down menu.
Additional OptionsadditionalOptionsobject

Additional parameters to be passed in the request. See the documentation for all available parameters.

Action Authentication

ReCharge uses API keys for authentication. When you connect your ReCharge account, Pipedream securely stores the keys so you can easily authenticate to ReCharge APIs in both code and no-code steps.

ReCharge uses API keys to authenticate requests. See docs.
Scopes can be set up from the API token edit page to control the level of access.

About ReCharge

Subscriptions & Recurring Payments for Ecommerce

More Ways to Connect ReCharge + Fauna

Cancel Subscription with ReCharge API on New or Removed Documents in a Collection from Fauna API
Fauna + ReCharge
 
Try it
Create Customer with ReCharge API on New or Removed Documents in a Collection from Fauna API
Fauna + ReCharge
 
Try it
Update Customer with ReCharge API on New or Removed Documents in a Collection from Fauna API
Fauna + ReCharge
 
Try it
Execute GraphQL Query with Fauna API on New Customer Created (Instant) from ReCharge API
ReCharge + Fauna
 
Try it
Import GraphQL schema with Fauna API on New Customer Created (Instant) from ReCharge API
ReCharge + Fauna
 
Try it
New or Removed Documents in a Collection from the Fauna API

Emit new event each time you add or remove a document from a specific collection, with the details of the document.

 
Try it
New Customer Created (Instant) from the ReCharge API

Emit new event when a new customer is created.

 
Try it
New Order Created (Instant) from the ReCharge API

Emit new event when a new order is created.

 
Try it
New Subscription Created (Instant) from the ReCharge API

Emit new event when a new subscription is created.

 
Try it
Execute GraphQL Query with the Fauna API

Performs an arbitrary authorized GraphQL query. See docs here

 
Try it
Import GraphQL schema with the Fauna API

Import graphQL schema to a database. See docs here

 
Try it
Read From Fauna Collection with the Fauna API

Reads all documents from a given Fauna collection. See docs here

 
Try it
Cancel Subscription with the ReCharge API

Cancels an existing subscription. See the documentation

 
Try it
Create Customer with the ReCharge API

Creates a customer. See the documentation

 
Try it

Explore Other Apps

1
-
24
of
2,500+
apps by most popular

HTTP / Webhook
HTTP / Webhook
Get a unique URL where you can send HTTP or webhook requests
Node
Node
Anything you can do with Node.js, you can do in a Pipedream workflow. This includes using most of npm's 400,000+ packages.
Python
Python
Anything you can do in Python can be done in a Pipedream Workflow. This includes using any of the 350,000+ PyPi packages available in your Python powered workflows.
Pipedream Utils
Pipedream Utils
Utility functions to use within your Pipedream workflows
OpenAI (ChatGPT)
OpenAI (ChatGPT)
OpenAI is an AI research and deployment company with the mission to ensure that artificial general intelligence benefits all of humanity. They are the makers of popular models like ChatGPT, DALL-E, and Whisper.
Premium
Salesforce
Salesforce
Cloud-based customer relationship management (CRM) platform that helps businesses manage sales, marketing, customer support, and other business activities, ultimately aiming to improve customer relationships and streamline operations.
Premium
HubSpot
HubSpot
HubSpot's CRM platform contains the marketing, sales, service, operations, and website-building software you need to grow your business.
Premium
Zoho CRM
Zoho CRM
Zoho CRM is an online Sales CRM software that manages your sales, marketing, and support in one CRM platform.
Premium
Stripe
Stripe
Stripe powers online and in-person payment processing and financial solutions for businesses of all sizes.
Shopify
Shopify
Shopify is a complete commerce platform that lets anyone start, manage, and grow a business. You can use Shopify to build an online store, manage sales, market to customers, and accept payments in digital and physical locations.
Premium
WooCommerce
WooCommerce
WooCommerce is the open-source ecommerce platform for WordPress.
Premium
Snowflake
Snowflake
A data warehouse built for the cloud
Premium
MongoDB
MongoDB
MongoDB is an open source NoSQL database management program.
Supabase
Supabase
Supabase is an open source Firebase alternative.
MySQL
MySQL
MySQL is an open-source relational database management system.
PostgreSQL
PostgreSQL
PostgreSQL is a free and open-source relational database management system emphasizing extensibility and SQL compliance.
Premium
AWS
AWS
Amazon Web Services (AWS) offers reliable, scalable, and inexpensive cloud computing services.
Premium
Twilio SendGrid
Twilio SendGrid
Send marketing and transactional email through the Twilio SendGrid platform with the Email API, proprietary mail transfer agent, and infrastructure for scalable delivery.
Amazon SES
Amazon SES
Amazon SES is a cloud-based email service provider that can integrate into any application for high volume email automation
Premium
Klaviyo
Klaviyo
Email Marketing and SMS Marketing Platform
Premium
Zendesk
Zendesk
Zendesk is award-winning customer service software trusted by 200K+ customers. Make customers happy via text, mobile, phone, email, live chat, social media.
Premium
ServiceNow
ServiceNow
The smarter way to workflow
Notion
Notion
Notion is a new tool that blends your everyday work apps into one. It's the all-in-one workspace for you and your team.
Slack
Slack
Slack is a channel-based messaging platform. With Slack, people can work together more effectively, connect all their software tools and services, and find the information they need to do their best work — all within a secure, enterprise-grade environment.