npm-registry-fetch icon indicating copy to clipboard operation
npm-registry-fetch copied to clipboard

[QUESTION] How should body option be formatted?

Open markcellus opened this issue 5 years ago • 6 comments

Hey @isaacs. Trying to use package. But I'm not quite sure if I'm using it correctly 😀 . when trying to pass the contents of package-lock.json to opts.body like this...

  const json = await npmFetch.json('/-/npm/v1/security/audits',  {
    method: 'POST',
    body: packageLockJsonContents, // this is just the contents of a package-lock.json parsed as an object
  });
  console.log(JSON.stringify(json, '', 3));

But I get the following error:

Failed to fetch audit report for repo npm. status: 400 cause: {"statusCode":400,"error":"Bad Request","message":"Invalid request payload input"}

How should the opts.body be formatted? Thanks!

markcellus avatar Sep 27 '20 01:09 markcellus

What is

typeof packageLockJsonContents

?

sosoba avatar Jan 05 '21 10:01 sosoba

object. But I was assuming the package would automatically JSON.stringify with proper content-type.

markcellus avatar Jan 07 '21 10:01 markcellus

sorry didn't mean to close this

markcellus avatar Jan 07 '21 10:01 markcellus

How come it is not still answered? How to use it? What should be the type of body option?

illicit-oblivion avatar May 21 '22 21:05 illicit-oblivion