

# CreateSubscriptionCheckoutSession

Subscribes a user to a plan or changes the user's current plan. The response returns exactly one outcome: payment is required (a checkout URL is returned), payment is not required (an effective date is returned), or, when no plan identifier is provided, plan selection is required (the hosted pricing page URL is returned). To make a one-time purchase of usage packs or add-ons, use CreateOneTimeCheckoutSession.

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

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

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

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

The request uses the following URI parameters.

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

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

 ** [userId](#API_CreateSubscriptionCheckoutSession_RequestSyntax) **   <a name="appmonetization-CreateSubscriptionCheckoutSession-request-uri-userId"></a>
The ID of the end user being subscribed. 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_CreateSubscriptionCheckoutSession_RequestBody"></a>

The request accepts the following data in JSON format.

 ** [clientToken](#API_CreateSubscriptionCheckoutSession_RequestSyntax) **   <a name="appmonetization-CreateSubscriptionCheckoutSession-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

 ** [planId](#API_CreateSubscriptionCheckoutSession_RequestSyntax) **   <a name="appmonetization-CreateSubscriptionCheckoutSession-request-planId"></a>
The plan to subscribe to or change to. Absent to open the hosted pricing page for the buyer to choose; the response then carries planSelectionRequired.pricingUrl.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 64.  
Pattern: `[a-z0-9-]+`   
Required: No

 ** [refreshUrl](#API_CreateSubscriptionCheckoutSession_RequestSyntax) **   <a name="appmonetization-CreateSubscriptionCheckoutSession-request-refreshUrl"></a>
The URL the buyer's browser is sent to if they cancel or abandon the hosted checkout page without completing payment (the checkout page's cancel-redirect target). Point it at a page where the buyer can retry. If you omit `planId`, the buyer chooses a plan on a hosted pricing page. After that checkout, the buyer returns to the hosted pages, not to this URL.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 2048.  
Required: Yes

 ** [returnUrl](#API_CreateSubscriptionCheckoutSession_RequestSyntax) **   <a name="appmonetization-CreateSubscriptionCheckoutSession-request-returnUrl"></a>
The URL the buyer's browser is sent to after they complete payment at checkout. If the buyer is sent to a hosted checkout page, this is that page's success-redirect target. If you omit `planId`, the buyer chooses a plan on a hosted pricing page. After that checkout, the buyer returns to the hosted pages, not to this URL.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 2048.  
Required: Yes

 ** [sessionDurationSeconds](#API_CreateSubscriptionCheckoutSession_RequestSyntax) **   <a name="appmonetization-CreateSubscriptionCheckoutSession-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 pricingUrl works; see expiresAt.  
Type: Integer  
Valid Range: Minimum value of 1. Maximum value of 86400.  
Required: No

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

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

{
   "outcome": { ... }
}
```

## Response Elements
<a name="API_CreateSubscriptionCheckoutSession_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.

 ** [outcome](#API_CreateSubscriptionCheckoutSession_ResponseSyntax) **   <a name="appmonetization-CreateSubscriptionCheckoutSession-response-outcome"></a>
The outcome of the request. Exactly one member of the union is set.  
Type: [CheckoutOutcome](API_CheckoutOutcome.md) object  
 **Note: **This object is a Union. Only one member of this object can be specified or returned.

## Errors
<a name="API_CreateSubscriptionCheckoutSession_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

 ** ConflictException **   
The request conflicts with the current state of the resource, such as a duplicate identifier or a version mismatch. Retrieve the current state of the resource and retry the request.    
 ** message **   
Human-readable description of the conflict.  
 ** resourceId **   
Identifier of the resource in a conflicting state.  
 ** resourceType **   
Type of the resource in a conflicting state.
HTTP Status Code: 409

 ** 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

 ** ServiceUnavailableException **   
The service is temporarily unavailable. Retry the request after the time in retryAfterSeconds.    
 ** message **   
Human-readable description of the service-unavailable condition.  
 ** retryAfterSeconds **   
Advice to clients on when the call can be safely retried.
HTTP Status Code: 503

 ** 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_CreateSubscriptionCheckoutSession_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/CreateSubscriptionCheckoutSession) 
+  [AWS SDK for .NET V4](https://docs.aws.amazon.com/goto/DotNetSDKV4/appmonetization-2022-07-26/CreateSubscriptionCheckoutSession) 
+  [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/appmonetization-2022-07-26/CreateSubscriptionCheckoutSession) 
+  [AWS SDK for Go v2](https://docs.aws.amazon.com/goto/SdkForGoV2/appmonetization-2022-07-26/CreateSubscriptionCheckoutSession) 
+  [AWS SDK for Java V2](https://docs.aws.amazon.com/goto/SdkForJavaV2/appmonetization-2022-07-26/CreateSubscriptionCheckoutSession) 
+  [AWS SDK for JavaScript V3](https://docs.aws.amazon.com/goto/SdkForJavaScriptV3/appmonetization-2022-07-26/CreateSubscriptionCheckoutSession) 
+  [AWS SDK for Kotlin](https://docs.aws.amazon.com/goto/SdkForKotlin/appmonetization-2022-07-26/CreateSubscriptionCheckoutSession) 
+  [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/appmonetization-2022-07-26/CreateSubscriptionCheckoutSession) 
+  [AWS SDK for Python (Boto3)](https://docs.aws.amazon.com/goto/boto3/appmonetization-2022-07-26/CreateSubscriptionCheckoutSession) 
+  [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/appmonetization-2022-07-26/CreateSubscriptionCheckoutSession) 