

# CreateBillingPortalSession

Opens the AWS App Monetization hosted customer billing portal for a user. This operation returns the billing portal URL that your application redirects the user's browser to. No state is persisted.

## Request Syntax
<a name="API_CreateBillingPortalSession_RequestSyntax"></a>

```
POST /apps/{{appId}}/users/{{userId}}/billing-portal-sessions?scope={{scope}} HTTP/1.1
Content-type: application/json

{
   "clientToken": "{{string}}",
   "refreshUrl": "{{string}}",
   "returnUrl": "{{string}}",
   "sessionDurationSeconds": {{number}}
}
```

## URI Request Parameters
<a name="API_CreateBillingPortalSession_RequestParameters"></a>

The request uses the following URI parameters.

 ** [appId](#API_CreateBillingPortalSession_RequestSyntax) **   <a name="appmonetization-CreateBillingPortalSession-request-uri-appId"></a>
The ID of the app the portal is for.  
Length Constraints: Minimum length of 1. Maximum length of 64.  
Pattern: `[A-Za-z0-9_-]+`   
Required: Yes

 ** [scope](#API_CreateBillingPortalSession_RequestSyntax) **   <a name="appmonetization-CreateBillingPortalSession-request-uri-scope"></a>
Required. The environment: live or sandbox.  
Valid Values: `sandbox | live`   
Required: Yes

 ** [userId](#API_CreateBillingPortalSession_RequestSyntax) **   <a name="appmonetization-CreateBillingPortalSession-request-uri-userId"></a>
The ID of the end user the portal is for. Do not include personally identifiable or otherwise sensitive data in this value.  
Length Constraints: Minimum length of 1. Maximum length of 128.  
Pattern: `[A-Za-z0-9_.~-]+`   
Required: Yes

## Request Body
<a name="API_CreateBillingPortalSession_RequestBody"></a>

The request accepts the following data in JSON format.

 ** [clientToken](#API_CreateBillingPortalSession_RequestSyntax) **   <a name="appmonetization-CreateBillingPortalSession-request-clientToken"></a>
A unique, case-sensitive identifier to ensure that the operation completes no more than one time. If this token matches a previous request, the service ignores the request but does not return an error.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 128.  
Pattern: `[!-~]+`   
Required: No

 ** [refreshUrl](#API_CreateBillingPortalSession_RequestSyntax) **   <a name="appmonetization-CreateBillingPortalSession-request-refreshUrl"></a>
A URL in your app. A plan checkout started from the portal doesn't redirect here: if the buyer cancels, they return to the portal's plans page. Bound into the session alongside returnUrl.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 2048.  
Required: Yes

 ** [returnUrl](#API_CreateBillingPortalSession_RequestSyntax) **   <a name="appmonetization-CreateBillingPortalSession-request-returnUrl"></a>
A URL in your app. A plan checkout started from the portal doesn't redirect here: after payment, the buyer returns to the portal's My subscription page. Bound into the session and reused for every checkout the buyer launches from the portal.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 2048.  
Required: Yes

 ** [sessionDurationSeconds](#API_CreateBillingPortalSession_RequestSyntax) **   <a name="appmonetization-CreateBillingPortalSession-request-sessionDurationSeconds"></a>
The lifetime of the hosted session, in seconds, counted from this call. Omit to use the service default. It does not set how long billingPortalUrl works; see expiresAt.  
Type: Integer  
Valid Range: Minimum value of 1. Maximum value of 86400.  
Required: No

## Response Syntax
<a name="API_CreateBillingPortalSession_ResponseSyntax"></a>

```
HTTP/1.1 201
Content-type: application/json

{
   "billingPortalUrl": "string",
   "expiresAt": number,
   "manageToken": "string",
   "sessionToken": "string"
}
```

## Response Elements
<a name="API_CreateBillingPortalSession_ResponseElements"></a>

If the action is successful, the service sends back an HTTP 201 response.

The following data is returned in JSON format by the service.

 ** [billingPortalUrl](#API_CreateBillingPortalSession_ResponseSyntax) **   <a name="appmonetization-CreateBillingPortalSession-response-billingPortalUrl"></a>
The URL of the billing portal page to redirect the end user's browser to. The URL carries a short-lived session token or a single-use link in its fragment. The link works once, until expiresAt or the end of the session if sooner.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 8192.

 ** [expiresAt](#API_CreateBillingPortalSession_ResponseSyntax) **   <a name="appmonetization-CreateBillingPortalSession-response-expiresAt"></a>
The time when the single-use link in `billingPortalUrl` expires, 10 minutes after it was created. After this time the URL no longer works and you must create a new session.  
Type: Timestamp

 ** [manageToken](#API_CreateBillingPortalSession_ResponseSyntax) **   <a name="appmonetization-CreateBillingPortalSession-response-manageToken"></a>
A short-lived token that authorizes updates to the buyer profile from the billing portal. Returned only with sessionToken.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 4096.

 ** [sessionToken](#API_CreateBillingPortalSession_ResponseSyntax) **   <a name="appmonetization-CreateBillingPortalSession-response-sessionToken"></a>
The billing portal session token carried in the fragment of billingPortalUrl. Absent when billingPortalUrl carries a single-use link instead.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 4096.

## Errors
<a name="API_CreateBillingPortalSession_Errors"></a>

For information about the errors that are common to all actions, see [Common Error Types](CommonErrors.md).

 ** AccessDeniedException **   
The caller does not have sufficient permission to perform this action.    
 ** message **   
Human-readable description of the access-denied condition.
HTTP Status Code: 403

 ** InternalServerException **   
An unexpected error occurred while processing the request.    
 ** message **   
Human-readable description of the server error.  
 ** retryAfterSeconds **   
Advice to clients on when the call can be safely retried.
HTTP Status Code: 500

 ** ResourceNotFoundException **   
The referenced resource does not exist.    
 ** message **   
Human-readable description of the missing resource.  
 ** resourceId **   
Identifier of the resource that was not found.  
 ** resourceType **   
Type of the resource that was not found (for example, "App" or "Plan").
HTTP Status Code: 404

 ** ThrottlingException **   
The request was denied due to request throttling.    
 ** message **   
Human-readable description of the throttling condition.  
 ** quotaCode **   
Service Quotas identifier for the throttled quota.  
 ** retryAfterSeconds **   
Advice to clients on when the call can be safely retried.  
 ** serviceCode **   
Service Quotas identifier for the originating service.
HTTP Status Code: 429

 ** ValidationException **   
The request failed input validation.    
 ** fieldList **   
The specific input fields that failed validation, when applicable.  
 ** message **   
Human-readable description of what failed validation.  
 ** reason **   
Machine-readable reason the request failed validation, so callers act without parsing the message.
HTTP Status Code: 400

## See Also
<a name="API_CreateBillingPortalSession_SeeAlso"></a>

For more information about using this API in one of the language-specific AWS SDKs, see the following:
+  [AWS Command Line Interface V2](https://docs.aws.amazon.com/goto/cli2/appmonetization-2022-07-26/CreateBillingPortalSession) 
+  [AWS SDK for .NET V4](https://docs.aws.amazon.com/goto/DotNetSDKV4/appmonetization-2022-07-26/CreateBillingPortalSession) 
+  [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/appmonetization-2022-07-26/CreateBillingPortalSession) 
+  [AWS SDK for Go v2](https://docs.aws.amazon.com/goto/SdkForGoV2/appmonetization-2022-07-26/CreateBillingPortalSession) 
+  [AWS SDK for Java V2](https://docs.aws.amazon.com/goto/SdkForJavaV2/appmonetization-2022-07-26/CreateBillingPortalSession) 
+  [AWS SDK for JavaScript V3](https://docs.aws.amazon.com/goto/SdkForJavaScriptV3/appmonetization-2022-07-26/CreateBillingPortalSession) 
+  [AWS SDK for Kotlin](https://docs.aws.amazon.com/goto/SdkForKotlin/appmonetization-2022-07-26/CreateBillingPortalSession) 
+  [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/appmonetization-2022-07-26/CreateBillingPortalSession) 
+  [AWS SDK for Python (Boto3)](https://docs.aws.amazon.com/goto/boto3/appmonetization-2022-07-26/CreateBillingPortalSession) 
+  [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/appmonetization-2022-07-26/CreateBillingPortalSession) 