> For the complete documentation index, see [llms.txt](https://roayati.gitbook.io/paypal-pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://roayati.gitbook.io/paypal-pro/actions/get-access-token.md).

# PayPal - Get Access Token

## PayPal - Get Access Token 🔑

This guide explains how to use the PayPal Get Access Token action in your Bubble.io application to obtain authentication tokens for PayPal Pro operations.

### Overview 📝

The Get Access Token action generates an OAuth 2.0 access token required for authenticating PayPal Pro requests. This token is necessary for operations like processing refunds and managing subscriptions.

### Prerequisites ✅

Before using this action, ensure you have:

* PayPal Business Account 💼
* **ALL** PayPal API Credentials configured in PayPal Pro plugin settings:
  * Client ID
  * Secret Key
  * Client ID - dev.
  * Secret Key - dev.
* SSL enabled on your bubble app (https) 🔒

### Input Parameters 📥

| Parameter | Type    | Description                                                |
| --------- | ------- | ---------------------------------------------------------- |
| Type      | Boolean | `true` for Sandbox (testing), `false` for Live environment |

### Response Output 📤

| Parameter | Type   | Description                             |
| --------- | ------ | --------------------------------------- |
| Token     | String | The access token for API operations     |
| Error     | String | Error message if token generation fails |

### How to Use 🛠️

#### Step 1: Add the Action

1. Create a new workflow in your Bubble editor
2. Click "Add an Action" ➕
3. Search for and select "PayPal - Get Access Token"

#### Step 2: Configure Environment

* Set the `Type` parameter:
  * For testing: Leave unchecked (Sandbox)
  * For production: Check the box (Live)

#### Step 3: Handle the Response

Set up workflow conditions based on the action's response:

```
When action is finished:
├── If token exists
│   └── Use token for subsequent PayPal operations
└── If error exists
    └── Handle error (show message, log error, etc.)
```

### Implementation Example 💡

Here's a typical workflow setup:

1. **Initialize Payment Process:**

```
Step 1: PayPal - Get Access Token

Step 2: Condition
        If access token is not empty
        Do: Continue with payment process
```

2. **Store Token for Multiple Operations:**

```
Step 1: PayPal - Get Access Token

Step 2: Store in Custom State
        token = Result's token

Step 3: Use stored token for subsequent API calls
(i.e ge subsciption details or cancel subscription .. etc)
```

### Best Practices 🎯

1. **Token Management:**
   * Store tokens temporarily for batch operations
   * Generate new tokens for sensitive operations
   * Don't store tokens in permanent storage
2. **Error Handling:**
   * Always check for error responses
   * Implement proper error messaging for users
   * Log errors for debugging
3. **Environment Management:**
   * Use Sandbox for testing
   * Double-check environment settings and keys before deployment

### Troubleshooting 🔧

Common issues and solutions:

1. **Token Generation Fails:**
   * Verify API credentials in plugin settings ***ALL FIELDS***
   * Check SSL certificate
   * Confirm PayPal account status
2. **Invalid Token Errors:**
   * Generate a new token
   * Verify environment settings
   * Check PayPal system status
3. **Authorization Errors:**
   * Confirm Client ID and Secret Key
   * Verify API permissions
   * Check account restrictions

### Security Considerations 🔐

1. Always use SSL/HTTPS
2. Never expose tokens in client-side code
3. Regenerate tokens for sensitive operations
4. Monitor token usage for suspicious activity

### Rate Limits ⚡

* Token requests are subject to PayPal's API rate limits
* Consider implementing token caching for high-volume operations
* Monitor API usage in PayPal Developer Dashboard

### Additional Resources 📚

* [PayPal API Documentation](https://developer.paypal.com/docs/api/overview/)
* [OAuth 2.0 Guide](https://developer.paypal.com/api/rest/authentication/)
* [Rate Limiting Guidelines](https://developer.paypal.com/docs/api/reference/api-requests/#rate-limiting)

Need help? Contact our support team roayati (@) gmail.com💬
