Skip to main content

Update Subscription API

Overview​

The Update Subscription API keeps a subscription created with Create Entitlement in step with your billing system: renewals, cancellations, expirations, refunds, and your own metadata.

A subscription has three times:

TimeMeaning
start_timestampStart of the paid period
end_timestampEnd of the paid period
grace_end_timestampWhen the user's token is revoked; default end_timestamp + 7 days

The token is revoked automatically at grace_end_timestamp (checked every few minutes, so allow up to about 10 minutes). Grace applies only while the subscription is active: for any other status the token is revoked at end_timestamp, unless you set grace_end_timestamp explicitly. An update that ends access now revokes the token during the call.

Always end a subscription with this API, not with Revoke or Revoke by SKU: those remove the token but leave the subscription active.


Endpoint​

POST /tnt/:tid/entitlement/subscription/update

Authentication​

This API requires tenant admin authorization.

Authorization: Bearer <token>

Path Parameters​

NameTypeRequiredDescription
tidstringYesTenant ID

Request Body​

Only the fields you send are changed.

FieldTypeRequiredDescription
trans_idstringYesThe trans_id returned by entitlement/add
statusstringNoactive, canceled, expired, or refunded
end_timestampISO8601 timestampNoNew end of the paid period
grace_end_timestampISO8601 timestampNoWhen the token is revoked; must not be before the end
keep_tokenbooleanNoWith status = refunded only: keep the token until the end
metadataobjectNoYour metadata; replaces any earlier metadata

cancelled is accepted for canceled.


Common Updates​

UpdateRequestResult
Renewend_timestampNew end; grace end moves to the new end + 7 days
Cancel (no renewal)status: canceledAccess continues to the end of the paid period
Expire nowstatus: expiredToken revoked immediately
Refundstatus: refundedToken revoked immediately
Refund, keep access to the endstatus: refunded, keep_token: trueToken revoked at the end of the paid period
Extend or shorten the grace periodgrace_end_timestampToken revoked at the new time
Reactivatestatus: active (optionally end_timestamp)Grace end returns to the end + 7 days
Record your own detailsmetadataStored with the subscription; nothing else changes

When you set status to expired or refunded without an end_timestamp, the end moves to now. When you send an end_timestamp with a new status, it is used as given.

After the Token Is Revoked​

Once the token has been revoked, the subscription is final: only metadata and a late status: refunded can be updated. To entitle the user again, create a new subscription with Create Entitlement.


Example Request​

curl -X POST "https://<fabric-authority-url>/tnt/<tenantId>/entitlement/subscription/update" \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"trans_id": "3pp:<tenantId>:pi_3pp_sub_5678",
"end_timestamp": "2027-01-15T00:00:00Z",
"metadata": { "renewal_invoice": "in_9876" }
}'

Response​

Success (HTTP 200)​

Returns the updated Subscription Record.

{
"message": "success",
"subscription": {
"sub_id": "3pp:<tenantId>:pi_3pp_sub_5678",
"user_addr": "0xabc123...",
"token_addr": "0xcontract456...",
"token_id": "62",
"tenant": "<tenantId>",
"status": "active",
"start_time": "2026-11-15T00:00:00Z",
"end_time": "2027-01-15T00:00:00Z",
"paid_to": "2027-01-15T00:00:00Z",
"grace_end": "2027-01-22T00:00:00Z",
"attributes": {
"sku": ["<svod-sku>"]
},
"metadata": {
"renewal_invoice": "in_9876"
},
"created": "2026-11-15T00:00:01Z",
"updated": "2026-12-14T09:12:40Z"
}
}

If an update ends access now but revoking the token fails, the update is still saved and the token is revoked automatically shortly after. The message then begins with updated; token revoke pending.

Errors​

Errors are returned as {"error": "<message>"}. For the invalid-value errors, the message is embedded in a longer string, so match on the text in the table rather than the whole string:

{
"error": "op [Resolve] kind [invalid] reason [keep_token only applies to status refunded]"
}
HTTPMessageMeaning
400trans_id is requiredtrans_id was omitted
400invalid request body: ...The body is not valid JSON or a field has the wrong type
404no subscription entitlement for trans_idNo subscription with that trans_id for this tenant
400invalid status: must be active, canceled, expired, or refundedUnknown status
400keep_token only applies to status refundedkeep_token sent without status: refunded
400end_timestamp must be after the subscription startend_timestamp is at or before the start
400grace_end_timestamp must not be before the endgrace_end_timestamp is earlier than the end
400subscription has ended and its token was revoked; use entitlement/add to re-entitleSee After the Token Is Revoked
400invalid metadatametadata could not be stored
500update failed: ...A server failure; retry the request