> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mayar.id/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Membership Invoice

> Endpoint to create (or reuse) an invoice for a membership member's current billing term.

```bash Request Example (productId in body) theme={null}
curl --request POST 'https://api.mayar.id/hl/v2/memberships/members/MBR8X2QK/invoice/create' \
--header 'Authorization: Bearer Paste-Your-API-Key-Here' \
--header 'Content-Type: application/json' \
--data-raw '{
    "productId": "7c9d2e1f-4a5b-4c6d-8e9f-0a1b2c3d4e5f"
}'
```

```bash Request Example (productId in query) theme={null}
curl --request POST 'https://api.mayar.id/hl/v2/memberships/members/MBR8X2QK/invoice/create?productId=7c9d2e1f-4a5b-4c6d-8e9f-0a1b2c3d4e5f' \
--header 'Authorization: Bearer Paste-Your-API-Key-Here'
```

```json Response Example 200 theme={null}
{
    "statusCode": 200,
    "message": "success",
    "data": {
        "id": "df65d192-8396-4f9a-b4e5-8244648c07c5",
        "transactionId": "ca87fd13-8742-4d48-af33-7de1a417bc34",
        "customerId": "a1b2c3d4-e5f6-4789-a012-3456789abcde",
        "membershipTierId": "9b2d4f6a-8c1e-4a3b-bd5c-6e7f8a9b0c1d",
        "amount": 150000,
        "status": "created",
        "expiredAt": "2026-07-20T09:10:57.994Z",
        "createdAt": "2026-06-20T09:10:57.994Z",
        "membershipBillUrl": "https://testingmayar.mayar.shop/pl/mbr9x2k7m3a"
    }
}
```

Endpoint:

```Production Production theme={null}
https://api.mayar.id/hl/v2/memberships/members/(memberId)/invoice/create
```

```Sandbox Sandbox theme={null}
https://api.mayar.io/hl/v2/memberships/members/(memberId)/invoice/create
```

## Authorization

**Authorization** `string` *required*

Example:

`Authorization | Bearer Paste-Your-API-Key-Here`

## Path Parameters

**memberId** `string` *required*

The unique identifier of the membership member to bill.

Example:

`MBR8X2QK`

## Request Body

`productId` may be supplied **in the request body OR as a query parameter** (see
[Query Parameters](#query-parameters)). At least one location is required.

**productId** `string` *required*

The unique identifier of the product the member belongs to. Accepted here in the
JSON body, or alternatively as a query parameter.

Example:

`7c9d2e1f-4a5b-4c6d-8e9f-0a1b2c3d4e5f`

## Query Parameters

**productId** `string`

Alternative location for `productId` when you prefer not to send a request body.
Use either the body field or this query parameter.

Example:

`?productId=7c9d2e1f-4a5b-4c6d-8e9f-0a1b2c3d4e5f`

## Idempotency (term-based)

Invoices are **idempotent per billing term**. The endpoint keys on the member's
current billing period: if an **unpaid** invoice already exists for the current
period it is reused and returned instead of creating a duplicate. Calling this
endpoint repeatedly within the same billing term therefore returns the same invoice
(and the same `membershipBillUrl`).

## Response

Successful Response

### Main Structure (Root Object)

**statusCode** `integer`

Status code from the API. `200` on success.

**message** `string`

Status message that describes the result. Note the **singular** `message` key
(write endpoints use `message`; read/list endpoints use the plural `messages`).

**data** `object`

The created (or reused) membership invoice object for the current billing term.

**data.id** `string`

The unique identifier of the invoice.

**data.transactionId** `string`

The identifier of the underlying transaction associated with the invoice.

**data.customerId** `string`

The identifier of the customer being billed.

**data.membershipTierId** `string`

The identifier of the member's tier.

**data.amount** `number`

The amount due for the billing term.

**data.status** `string`

Current status of the invoice (for example `created`).

**data.expiredAt** `string`

Invoice expiration time in ISO 8601 format (UTC).

**data.membershipBillUrl** `string`

The membership bill URL the customer can use to pay. Built from the tenant's shop
subdomain in the shape `https://<tenant>.mayar.shop/pl/<link>` — this is **not** an
`api.mayar.id` URL.

## Errors

All errors use the envelope `{ "statusCode": <code>, "message": "<reason>" }` (singular `message`).

```json Error Example 400 theme={null}
{
    "statusCode": 400,
    "message": "Invalid request body"
}
```

**statusCode** `integer`

The HTTP status code of the error.

**message** `string`

A human-readable description of the error.

Common errors:

| Status | `message` | When |
| - | - | - |
| `400` | `Invalid path parameter` | `memberId` is missing or malformed in the path. |
| `400` | `Invalid request body` | `productId` is missing from both the body and the query, or the request fails validation. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.