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.

[Deno] Invalid JSON received from the Stripe API

See original GitHub issue

Describe the bug

stripe.accounts.createLoginLink throws error when executed in Deno environment.

To Reproduce

  1. Create index.ts file
  2. Add code
  3. Run via Deno
  4. Get error

Expected behavior

Request to execute successfully

Code snippets

// errors
const loginLink = await stripe.accounts.createLoginLink('acct_1LZWJGPPxRBiNZOx')

// works fine
const loginLink = await fetch(
  `https://api.stripe.com/v1/accounts/${'acct_1LZWJGPPxRBiNZOx'}/login_links`,
  {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${Deno.env.get('STRIPE_API_KEY')}`,
    },
  }
).then((res) => res.json())

OS

macOS 11.06.1

Node version

Deno version: { deno: “1.20.3”, v8: “10.0.139.6”, typescript: “4.6.2” }

Library version

https://esm.sh/stripe@9.6.0?target=deno&no-check

API version

2020-08-27

Additional context

Related discussion on StripeDev Discord

Potentially related to https://github.com/stripe/stripe-node/issues/954 ?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
dcr-stripecommented, Aug 22, 2022

The root cause issue here is Deno injects its own Content-Length header despite stripe-node providing a value for it, so the end request has this header twice and nginx returns a 400. I’ve filed https://github.com/denoland/deno/issues/15545 on the Deno side for this.

I’ll investigate to see if we can fix this from the Stripe side in the interim.

1reaction
dcr-stripecommented, Aug 23, 2022

Hi @thorwebdev - thanks for the patience here!

I’ve released the fix under stripe-node@10.4.0-beta.1 . It now works for me. Could you try it out with your code just to double check, and if all works, I’ll release it to the main stable channel?

You can try this out using:

import Stripe from "https://esm.sh/stripe@10.4.0-beta.1?target=deno";

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid JSON from Stripe - Stack Overflow
Trying to use Stripe with Parse via a "Cloud Function". I made a couple of charges as of yesterday but now it stopped...
Read more >
How to Fix SyntaxError: Unexpected token < in JSON at ...
Usually this error is caused when your server returns HTML (which typically begins with <DOCTYPE html> or <html> ) instead of JSON. Valid...
Read more >
Stripe API Redirect to Checkout Not Working Reactjs + Nextjs
Project: Small eCommerce site using Stripe API for payments. ... SyntaxError: Unexpected token 'I', "Invalid re"... is not valid JSON.
Read more >
Edge Functions Quickstart - Supabase
If you receive an error Invalid JWT , find the ANON_KEY of your project in the Dashboard under Settings > API . After...
Read more >
JSON Schema Store
JSON Schemas for common JSON file formats. ... Public API for JSON Schemas The JSON API contains a list of JSON Schema files...
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