Skip to main content

Documentation

Update Invoice

Change or modify an invoice.

You can modify the invoice when its status is draft.

This method triggers the Invoice Updated Webhook. This webhook contains the same information as the response.

    • invoice

    • ID of the invoice you want to update. String starting with invoice_.

Code Samples
    • .NET

      • using System;
        using System.Text.Json;
        
        namespace RapydApiRequestSample
        {
            class Program
            {
                static void Main(string[] args)
                {
                    try
                    {
                        string invoiceId = "invoice_e722956a315d42c94e93ce49153e7029";
        
                        var requestObj = new
                        {
                            days_until_due = 40,
                            metadata = new
                            {
                                merchant_defined = "updated"
        
                            }
                        };
        
                        string request = JsonSerializer.Serialize(requestObj);
        
                        string result = RapydApiRequestSample.Utilities.MakeRequest("POST", $"/v1/invoices/{invoiceId}", 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 = {
              days_until_due: 40
            };
            const result = await makeRequest(
              'POST',
              '/v1/invoices/invoice_e722956a315d42c94e93ce49153e7029',
              body
            );
        
            console.log(result);
          } catch (error) {
            console.error('Error completing request', error);
          }
        }
    • PHP

      • <?php
        $path .= "/<path-to-your-utility-file>/utilities.php";
        include($path);
        
        $body = [
            "metadata" => array(
                "merchant_defined" => "updated"
            ),
            "days_until_due" => 40
        ];
        
        try {
            $object = make_request('post', "/v1/invoices/invoice_e722956a315d42c94e93ce49153e7029", $body);
            var_dump($object);
        } catch(Exception $e) {
            echo "Error => $e";
        }
        ?>
    • Python

      • from pprint import pprint
        
        from utilities import make_request
        
        invoice = {
            "metadata": {
                "merchant_defined": "updated"
            },
            "days_until_due": 40
        }
        result = make_request(method='post', path='/v1/invoices/invoice_e722956a315d42c94e93ce49153e7029', body=invoice)
        pprint(result)
        
  • /v1/invoices/:invoice

  • Update Invoice

  • curl -X post 'https://sandboxapi.rapyd.net/v1/invoices/invoice_20d154c968ea36429ec5bc688254d0b1' \
    -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' \
    --data-raw '{
        "days_until_due": 40,
        "metadata": {
            "merchant_defined": "updated"
        }
    }'
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "1f7f6289-4645-453c-8130-37d2b107ad75"
        },
        "data": {
            "id": "invoice_20d154c968ea36429ec5bc688254d0b1",
            "attempt_count": 0,
            "billing": "pay_automatically",
            "billing_reason": "manual",
            "created_at": 1764744320,
            "currency": "USD",
            "customer": "cus_4e25112ac20e144ad073a614dc46934b",
            "description": "",
            "discount": null,
            "due_date": 1768200320,
            "days_until_due": 40,
            "metadata": {
                "merchant_defined": "updated"
            },
            "payment_method": "card_b9548d9b53a565b2315fecdc6c87f158",
            "payment": null,
            "payout": null,
            "payment_fields": null,
            "period_end": 0,
            "period_start": 0,
            "lines": [],
            "statement_descriptor": "",
            "subscription": "",
            "discount_amount": 0,
            "subtotal": 0,
            "tax": 0,
            "tax_percent": 0,
            "total": 0,
            "status": "draft",
            "payout_fields": null,
            "type": "payment"
        }
    }
  • Bad Request - Days Until Due Not Valid

  • curl -X post 'https://sandboxapi.rapyd.net/v1/invoices/invoice_0ae79d418ce7a51029d8fba31b6eec2c' \
    -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' \
    --data-raw '{
        "days_until_due": 770
    }'
  • {
        "status": {
            "error_code": "ERROR_DAYS_UNTIL_DUE_NOT_VALID",
            "status": "ERROR",
            "message": "The request tried to set or update the 'days_until_due' parameter in an invoice or subscription, but the value was not valid. The request was rejected. Corrective action: Set 'days_until_due' to a positive integer.",
            "response_code": "ERROR_DAYS_UNTIL_DUE_NOT_VALID",
            "operation_id": "e6a05b7b-4edb-4e93-a462-fda1aa3fa1ae"
        }
    }
  • Bad Request - Due Date Not Valid

  • curl -X post 'https://sandboxapi.rapyd.net/v1/invoices/invoice_0ae79d418ce7a51029d8fba31b6eec2c' \
    -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' \
    --data-raw '{
        "due_date": "2026-06-01"
    }'
  • {
        "status": {
            "error_code": "INVALID_DUE_DATE",
            "status": "ERROR",
            "message": "The request tried to set or update the due date of an invoice, but the value was not valid. The request was rejected. Corrective action: Set the 'due_date' body parameter to a valid Unix timestamp in the future.",
            "response_code": "INVALID_DUE_DATE",
            "operation_id": "52e8c775-95ba-4e74-9ffc-da9d1d86b498"
        }
    }