Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm just beginning to play with the Stripe API, and already I've hit something I don't understand:

How do I determine the identifer (e.g., acct_abcd1234blablabla) of my own Stripe account?

I'm not seeing any sort of account identifier in my temporary Stripe test account (although maybe I'm just not looking under the proper tab of the Account Settings pane).

Now, the documentation for "Retrieve Account" says:

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

And it seems like omitting the account identifier from the URI would be a perfectly reasonable way of getting one's own account identifier, since it should be a property of the returned JSON object. But I can't figure out how to omit the argument in a way that causes the account object to be returned.

Given that the example invocation, with an explicit account identfier argument, looks like:

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

my expectation is that simply omitting the final element of that URI will get me the default. But if I do that:

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

I get:

{
  "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/."    
  }
}

Of course, if I do something silly like omit the trailing slash as well:

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

I get, understandably enough, the (empty) list of connected accounts, which is not what I'm after:

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

So, what am I missing here?

  • What's the right way to specify "use the default" in GET /v1/accounts/?
  • Or, alternatively, how do I find my account identifier via my Stripe account dashboard?

(Parenthetically, I'll note that the API examples show me a valid account identifier corresponding to the private key they show me, and all of this may somehow be magically coordinated with my dashboard session, which shows me the same private key. But this hardly seems like the right way to obtain one's own account identifier in a real application.)

like image 783
Hephaestus Avatar asked Nov 12 '16 23:11

Hephaestus


1 Answers

If you call the Retrieve Account API without any parameter it will give you details about your own account. If you want to do it in curl, you'd simply hit /v1/account without an s at the end:

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

This is what the SDKs do. You can see what the PHP SDK does here:

public function instanceUrl()
{
    if ($this['id'] === null) {
        return '/v1/account';
    } else {
        return parent::instanceUrl();
    }
}
like image 185
koopajah Avatar answered Sep 30 '22 17:09

koopajah