Skip to main content

Documentation

Create Usage Record

Create a usage record or update an existing usage record where its unique identifier is composed of timestamp and subscription_item.

    • subscription_item

    • ID of the subscription item. String starting with subi_.

Code Samples
    • .NET

      • using System;
        using System.Text.Json;
        
        namespace RapydApiRequestSample
        {
            class Program
            {
                static void Main(string[] args)
                {
                    try
                    {
                        string subscriptionItem = "subi_3682d7bce9339f7b7c9e4185c7d1486f";
        
                        var requestObj = new
                        {
                            quantity = 10,
                            timestamp = 1560866720,
                            action = "increment",
                            metadata = new
                            {
                                merchant_defined = true
                            }
                        };
        
                        string request = JsonSerializer.Serialize(requestObj);
        
                        string result = RapydApiRequestSample.Utilities.MakeRequest("POST", $"/v1/subscription_items/{subscriptionItem}/usage_records", 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 = {
              quantity: 10,
              timestamp: '1560866720',
              action: 'increment',
              metadata: {
                merchant_defined: true
              }
            };
            const result = await makeRequest(
              'POST',
              '/v1/subscription_items/subi_3682d7bce9339f7b7c9e4185c7d1486f/usage_records',
              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);
        
        $body = [
           "quantity" => "10",
           "timestamp" => "1560866720",
           "action"  => "increment",
           "metadata" => array(
                                "merchant_defined" => true
           )
        ];
        
        try {
            $object = make_request('post', '/v1/subscription_items/subi_3682d7bce9339f7b7c9e4185c7d1486f/usage_records', $body);
            var_dump($object);
        } catch(Exception $e) {
            echo "Error: $e";
        }
        ?>
    • Python

      • from pprint import pprint
        
        from utilities import make_request
        
        subscription_item = "subi_3682d7bce9339f7b7c9e4185c7d1486f"
        usage_record_body = {
            "quantity": "10",
            "timestamp": "1560866720",
            "action": "increment"
        }
        response = make_request(method='post',
                                path=f'/v1/subscription_items/{subscription_item}/usage_records',
                                body=usage_record_body)
        
        pprint(response)
  • /v1/subscription_items/{subscription_item}/usage_records

  • Create Usage Record

  • curl -X post
    https://sandboxapi.rapyd.net/v1/subscription_items/subi_3682d7bce9339f7b7c9e4185c7d1486f/usage_records
    -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 '{
        "quantity": "10",
        "timestamp": "1560866720",
        "action": "increment",
        "metadata": {
            "merchant_defined": true
        }
    }'
    
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "cd558017-6794-4d21-a2a8-9c899624c113"
        },
        "data": {
            "id": "subiur_02546407684c46ef0077a50db8e2b8f7",
            "quantity": 10,
            "timestamp": "1560866720",
            "subscription_item": "subi_3682d7bce9339f7b7c9e4185c7d1486f",
            "metadata": {
                "merchant_defined": true
            }
        }
    }