# 連結アカウントに対する API コールの実行

サーバーまたはクライアントで、連結アカウントに対して API コールを実行する方法を説明します。

サーバーまたはクライアントで、連結アカウントに対して API コールを実行できます。

- **サーバー側**: 各リクエストの `Stripe-Account` ヘッダーに連結アカウントの ID を含めます
- **クライアント側**: 連結アカウントの ID を引数としてクライアントライブラリに渡します

パフォーマンスと信頼性を高めるために、Stripe では API エンドポイントに対して[レート制限と割り当て](https://docs.stripe.com/rate-limits.md)を設定しています。

## サーバー側で Stripe-Account ヘッダーを追加する

連結アカウントに対してサーバー側の API コールを実行するには、`acct_` で始まる [アカウント](https://docs.stripe.com/api/accounts.md) ID を指定した `Stripe-Account` ヘッダーを使用します。プラットフォームの [API シークレットキー](https://docs.stripe.com/keys.md)と連結アカウントの`アカウント` ID を使用する 4 つの例を以下に示します。

#### PaymentIntent を作成

```curl
curl https://api.stripe.com/v1/payment_intents \
  -u "<<YOUR_SECRET_KEY>>:" \
  -H "Stripe-Account: {{CONNECTED_ACCOUNT_ID}}" \
  -d amount=1000 \
  -d currency=usd
```

#### 残高の取得

```curl
curl https://api.stripe.com/v1/balance \
  -u "<<YOUR_SECRET_KEY>>:" \
  -H "Stripe-Account: {{CONNECTED_ACCOUNT_ID}}"
```

#### 商品のリスト化

```curl
curl -G https://api.stripe.com/v1/products \
  -u "<<YOUR_SECRET_KEY>>:" \
  -H "Stripe-Account: {{CONNECTED_ACCOUNT_ID}}" \
  -d limit=5
```

#### 顧客の削除

```curl
curl -X DELETE https://api.stripe.com/v1/customers/{{CUSTOMER_ID}} \
  -u "<<YOUR_SECRET_KEY>>:" \
  -H "Stripe-Account: {{CONNECTED_ACCOUNT_ID}}"
```

URL に `Account` ID が含まれる API リクエストでは、黙示的に `Stripe-Account` ヘッダーを使用する方法が採用されます。この例では、リクエスト URL に ID を含めて[アカウントを取得する](https://docs.stripe.com/api/v2/core/accounts/retrieve.md)方法を示します。

> 連結アカウントを取得する際に [Accounts v2 API](https://docs.stripe.com/connect/accounts-v2.md) を使用することを推奨します。

```curl
curl https://api.stripe.com/v2/core/accounts/{{CONNECTED_ACCOUNT_ID}} \
  -H "Authorization: Bearer <<YOUR_SECRET_KEY>>" \
  -H "Stripe-Version: 2026-11-18.preview"
```

Stripe のすべてのサーバ側ライブラリでは、この方法がリクエストごとにサポートされます。

```curl
curl https://api.stripe.com/v1/customers \
  -u "<<YOUR_SECRET_KEY>>:" \
  -H "Stripe-Account: {{CONNECTED_ACCOUNT_ID}}" \
  --data-urlencode "email=person@example.com"
```

## クライアント側の申し込みに連結アカウントの ID を追加する

クライアント側ライブラリでは、連結アカウントの ID がクライアントアプリケーションへの引数として設定されます。

#### HTML + JS

連結アカウントの ID をクライアント側で渡すための JavaScript コードは、プレーン JS および ESNext の場合と同じです。

```javascript
var stripe = Stripe('<<YOUR_PUBLISHABLE_KEY>>', {
  stripeAccount: '{{CONNECTED_ACCOUNT_ID}}',
});
```

#### React

```javascript
import {loadStripe} from '@stripe/stripe-js';

// Make sure to call `loadStripe` outside of a component's render to avoid
// recreating the `Stripe` object on every render.
const stripePromise = loadStripe('<<YOUR_PUBLISHABLE_KEY>>', {
  stripeAccount: '{{CONNECTED_ACCOUNT_ID}}',
});
```

#### iOS

#### Swift

```swift
import UIKit
import StripePayments

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        StripeAPI.defaultPublishableKey = "<<YOUR_PUBLISHABLE_KEY>>"
        STPAPIClient.shared.stripeAccount = "{{CONNECTED_ACCOUNT_ID}}"
        return true
    }
}
```

#### Android

#### Kotlin

```kotlin
import com.stripe.android.PaymentConfiguration

class MyActivity: Activity() {
    private lateinit var stripe: Stripe

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        stripe = Stripe(
            this,
            PaymentConfiguration.getInstance(this).publishableKey,
            "{{CONNECTED_ACCOUNT_ID}}"
        )
    }
}
```

#### React Native

```jsx
import {StripeProvider} from '@stripe/stripe-react-native';

function App() {
  return (
    <StripeProvider
      publishableKey="<<YOUR_PUBLISHABLE_KEY>>"
      stripeAccountId="{{CONNECTED_ACCOUNT_ID}}"
    >
      {/* Your app code here */}
    </StripeProvider>
  );
}
```

## Connect 埋め込みコンポーネントの使用

Stripe の API と直接連携する代わりに、[連結する埋め込みコンポーネント](https://docs.stripe.com/connect/get-started-connect-embedded-components.md)を使用して、プラットフォームの UI で連結アカウントに Stripe 機能を提供できます。これらのコンポーネントでは、すべての API コールを内部で実装して処理するためのコードが少なくて済みます。

たとえば、連結アカウントに Payments データを表示するには、プラットフォームの UI に [決済コンポーネント](https://docs.stripe.com/Connect/supported-embedded-components/payments.md)を埋め込みます。これにより、[Charges](https://docs.stripe.com/API/charges.md)、[Payment Intents](https://docs.stripe.com/API/payment_intents.md)、[Refunds](https://docs.stripe.com/API/refunds.md)、および [Disputes](https://docs.stripe.com/API/disputes.md) API を個別に呼び出す必要がなくなります。

Note: The following is a preview/demo component that behaves differently than live mode usage with real connected accounts. The actual component has more functionality than what might appear in this demo component. For example, for connected accounts without Stripe dashboard access (custom accounts), no user authentication is required in production.

使用可能な埋め込みコンポーネントの一覧については、[対応コンポーネント](https://docs.stripe.com/connect/supported-embedded-components.md)をご覧ください。

## See also

- [支払いを作成する](https://docs.stripe.com/connect/charges.md)
- [サブスクリプションを使用する](https://docs.stripe.com/connect/subscriptions.md)
- [Connect 埋め込みコンポーネントを始める](https://docs.stripe.com/connect//get-started-connect-embedded-components.md)
