Skip to main content

Documentation

Create Subscription Item

Create a subscription item and add it to an existing subscription for recurring payment.

To add a non-recurring charge to a subscription invoice, see Create Invoice.

This method triggers the Customer Subscription Item Created webhook. This webhook contains the same information as the response.

Code Samples
    • .NET

      • using System;
        using System.Text.Json;
        
        namespace RapydApiRequestSample
        {
            class Program
            {
                static void Main(string[] args)
                {
                    try
                    {
                        var requestObj = new
                        {
                            plan = "plan_dad429f5e16c41499c9c23356a5e8dea",
                            subscription = "sub_0de9c79c1e2beee09499dc8220493d59",
                            metadata = new
                            {
                                merchant_defined = true
                            },
                            quantity = 1
                        };
        
                        string request = JsonSerializer.Serialize(requestObj);
        
                        string result = RapydApiRequestSample.Utilities.MakeRequest("POST", "/v1/subscription_items", request);
                        Console.WriteLine(result);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error completing request: " + e.Message);
                    }
                }
            }
        }
        
    • JavaScript

      • const makeRequest = require('<path-to-your-utility-file>/utilities').makeRequest;
        
        async function main() {
          try {
            const body = {
              plan: 'plan_dad429f5e16c41499c9c23356a5e8dea',
              subscription: 'sub_0de9c79c1e2beee09499dc8220493d59',
              metadata: {
                merchant_defined: true
              },
              quantity: 1
            };
            const result = await makeRequest('POST', '/v1/subscription_items', body);
        
            console.log(result);
          } catch (error) {
            console.error('Error completing request', error);
          }
        }
        
    • PHP

      • <?php
        $path = $_SERVER['DOCUMENT_ROOT'];
        $path .= "<path-to-your-utility-file>/utilities.php";
        include($path);
        
        try {
            $subscription_items = [
                "plan" => "plan_dad429f5e16c41499c9c23356a5e8dea",
                "subscription" => "sub_0de9c79c1e2beee09499dc8220493d59",
                            "metadata" => array(
                    "merchant_defined" => true
                ),
                "quantity" => 1
            ];
            $object = make_request('post', '/v1/subscription_items', $subscription_items);
            var_dump($object);
        } catch(Exception $e) {
            echo "Error: $e";
        }
        ?>
    • Python

      • from pprint import pprint
        
        from utilities import make_request
        
        subscription_item = {
            "plan": "plan_dad429f5e16c41499c9c23356a5e8dea",
            "subscription": "sub_0de9c79c1e2beee09499dc8220493d59",
            "metadata": {
                "merchant_defined": True
            },
            "quantity": 1
        }
        
        result = make_request(method='post', path='/v1/subscription_items', body=subscription_item)
        pprint(result)
        
  • /v1/subscription_items

  • Create Subscription Item

  • curl -X post
    https://sandboxapi.rapyd.net/v1/subscription_items
    -H 'access_key: your-access-key-here'
    -H 'Content-Type: application/json'
    -H 'idempotency: your-idempotency-parameter-here'
    -H 'salt: your-random-string-here'
    -H 'signature: your-calculated-signature-here'
    -H 'timestamp: your-unix-timestamp-here'
    -d '{
        "plan": "plan_dad429f5e16c41499c9c23356a5e8dea",
        "subscription": "sub_0de9c79c1e2beee09499dc8220493d59",
        "metadata": {
            "merchant_defined": true
        },
        "quantity": 1
    }
    '
    
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "710f52ac-5418-40ea-8e85-a2259bd288bb"
        },
        "data": {
            "id": "subi_e5dbbf84c68e5bb7db761625158d4262",
            "created": 1560329454,
            "metadata": null,
            "quantity": 1,
            "subscription_id": "sub_0de9c79c1e2beee09499dc8220493d59",
            "plan": {
                "id": "plan_dad429f5e16c41499c9c23356a5e8dea",
                "aggregate_usage": "sum",
                "amount": 0,
                "billing_scheme": "per_unit",
                "created_at": 1559803170,
                "currency": "USD",
                "interval": "month",
                "interval_count": 1,
                "metadata": {},
                "product": "product_97f34708270f13d95d9c505eb785e3c5",
                "nickname": "",
                "tiers": [],
                "tiers_mode": "",
                "transform_usage": {
                    "divide_by": 0,
                    "round": ""
                },
                "trial_period_days": 0,
                "usage_type": "metered"
            }
        }
    }