Stripe API:我的账户 ID 是什么?如何在 GET /v1/accounts/ 中默认它?

Stripe API: What's my account ID? How to default it in GET /v1/accounts/?

我刚开始玩 Stripe API,我已经遇到了一些我不明白的东西:

如何确定我自己的 Stripe 帐户的标识符(例如, acct_abcd1234blablabla)?

我在我的临时 Stripe 测试帐户中没有看到任何类型的帐户标识符(尽管我可能只是没有在“帐户设置”窗格的正确选项卡下查看)。

现在,“Retrieve Account”的文档说:

ARGUMENTS
account [optional]
The identifier of the account to be retrieved. If none is provided, will default to the account of the API key.

从 URI 中省略帐户标识符似乎是 获取自己帐户标识符的一种完全合理的方式,因为它应该是 属性返回的 JSON 对象。但我不知道如何以导致返回帐户对象的方式省略参数。

鉴于带有显式帐户标识符参数的示例调用如下所示:

curl https://api.stripe.com/v1/accounts/acct_abcd1234blablabla -u sk_test_foobarbaz:

我的期望是,只需省略该 URI 的最后一个元素即可获得默认值。但如果我这样做:

curl https://api.stripe.com/v1/accounts/ -u sk_test_foobarbaz:

我得到:

{
  "error": {
    "type": "invalid_request_error",
    "message": "Unrecognized request URL (GET: /v1/accounts/). Please see https://stripe.com/docs or we can help at https://support.stripe.com/."    
  }
}

当然,如果我做一些愚蠢的事情,比如省略尾部斜线:

curl https://api.stripe.com/v1/accounts -u sk_test_foobarbaz:

我明白了,已连接帐户的(空)列表,这不是我想要的:

{
  "object": "list",
  "data": [],
  "has_more": false,
  "url": "/v1/accounts"
}

那么,我在这里缺少什么?

(顺便说一句,我会注意到 API 示例向我展示了一个有效的帐户标识符,该标识符对应于他们向我展示的私钥,并且所有这些都可能以某种方式与我的仪表板会话神奇地协调,这向我展示了相同的私钥。但这看起来不像是在实际应用程序中获取自己帐户标识符的正确方法。)

如果您不带任何参数调用检索帐户 API,它将为您提供有关您自己帐户的详细信息。如果你想在卷曲中做到这一点,你只需点击 /v1/account 最后没有 s:

curl https://api.stripe.com/v1/account -u sk_test_foobar:

这就是 SDK 的作用。你可以看看 PHP SDK 做了什么 here:

public function instanceUrl()
{
    if ($this['id'] === null) {
        return '/v1/account';
    } else {
        return parent::instanceUrl();
    }
}