question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StripeAuthenticationError error on stripeAPI.paymentMethods.list

See original GitHub issue

Hi there,

when I try to list specific customer as stated here:

stripe.paymentMethods.list({customer: 'customerid', type: 'card'});

I got 400 with following result

type: 'StripeInvalidRequestError',
  raw: {
    message: 'Invalid string: {:customer=>"cus_HngFprv2g3XFJQ"}',   
    param: 'customer',
    type: 'invalid_request_error',
    headers: {
      server: 'nginx',
      date: 'Sun, 09 Aug 2020 03:17:53 GMT',
      'content-type': 'application/json',
      'content-length': '157',
      connection: 'keep-alive',
      'access-control-allow-credentials': 'true',
      'access-control-allow-methods': 'GET, POST, HEAD, OPTIONS, DELETE',
      'access-control-allow-origin': '*',
      'access-control-expose-headers': 'Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required',
      'access-control-max-age': '300',
      'cache-control': 'no-cache, no-store',
      'request-id': 'req_SzhsHOVznnqQRd',
      'stripe-version': '2020-03-02',
      'strict-transport-security': 'max-age=31556926; includeSubDomains; preload'
    },

but why?

image

And I fixed this issue but using

stripe.paymentMethods.list(customer, 'card'});

and result became

 type: 'StripeAuthenticationError',
  raw: {
    message: 'Invalid API Key provided: card',
    type: 'invalid_request_error',
    headers: {
      server: 'nginx',
      date: 'Sun, 09 Aug 2020 03:14:35 GMT',
      'content-type': 'application/json',
      'content-length': '106',
      connection: 'keep-alive',
      'access-control-allow-credentials': 'true',
      'access-control-allow-methods': 'GET, POST, HEAD, OPTIONS, DELETE',
      'access-control-allow-origin': '*',
      'access-control-expose-headers': 'Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required',
      'access-control-max-age': '300',
      'cache-control': 'no-cache, no-store',
      'www-authenticate': 'Bearer realm="Stripe"',
      'strict-transport-security': 'max-age=31556926; includeSubDomains; preload'
    },
    statusCode: 401,
    requestId: undefined
  },
  rawType: 'invalid_request_error',
  code: undefined,
  doc_url: undefined,
  param: undefined,
  detail: undefined,
  headers: {
    server: 'nginx',
    date: 'Sun, 09 Aug 2020 03:14:35 GMT',
    'content-type': 'application/json',
    'content-length': '106',
    connection: 'keep-alive',
    'access-control-allow-credentials': 'true',
    'access-control-allow-methods': 'GET, POST, HEAD, OPTIONS, DELETE',
    'access-control-allow-origin': '*',
    'access-control-expose-headers': 'Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required',
    'access-control-max-age': '300',
    'cache-control': 'no-cache, no-store',
    'www-authenticate': 'Bearer realm="Stripe"',
    'strict-transport-security': 'max-age=31556926; includeSubDomains; preload'
  },
  requestId: undefined,
  statusCode: 401,
  charge: undefined,
  decline_code: undefined,
  payment_intent: undefined,
  payment_method: undefined,
  setup_intent: undefined,
  source: undefined
}

Weird thing is, it works with curl

https://api.stripe.com/v1/payment_methods?customer=cus_id&type=card

My Stripe SDK Version: stripe": "^8.84.0 but I also tried with “stripe”: “^8.79.0”, before update

My node version is => v12.18.2

OS Windows 10

Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
remi-stripecommented, Aug 9, 2020

It uses 'card' as your API key, which is invalid, so that’s why you get a 401.

0reactions
BerkanCetinkayaOSFcommented, Aug 9, 2020

401 just means you’re passing an invalid API key or an empty API key when making the call.

I know what it means. Can you please check this?

var stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');

(async () => {
    var pms = await stripe.paymentMethods.list(
        {
            customer: 'cus_HngizKHWPRaujW'
        },
        'card'
    ).catch(console.log);
})();

IMO, 400 makes sense here

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error codes | Stripe Documentation
See the documentation on payment errors for an example. Below is a list of possible error codes, along with additional information about how...
Read more >
node.js - Stripe Api is having issue while creating a payment
when i try to execute this my data is successfully be stored in database but unfortunately when it comes with stripe api it...
Read more >
stripe | Yarn - Package Manager
The Stripe Node library provides convenient access to the Stripe API from applications written in server-side JavaScript.
Read more >
Error payment_methods · Issue #636 · stripe/stripe-node
I am using Stripe API 6.36.0 and node 8.4 Initial request from the Stripe ... As if I need to create the paymentMethod...
Read more >
Stripe.PaymentMethod — stripity_stripe v2.17.2 - HexDocs
Stripe API reference: https://stripe.com/docs/api/payment_methods ... List all payment methods. retrieve(id, opts \\ []). Retrieve a payment method.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found