#10428·kubo

api/v0/resolve returns invalid JSON

Author: SgtPookiCreated May 21, 2024Updated Sep 8, 2026
Labelskind/bugP2

Checklist

Installation method

ipfs-update or dist.ipfs.tech

Version

0.27.0

Config

json
lmk if you really need it

Description

i'm working on gateway conformance tests in @helia/verified-fetch and ran into issues with resolving IPFS_NS_MAP peerIds when calling the ${kuboGateway}/api/v0/resolve/${peerId} endpoint:

basic-server:dns response from Kubo: 
'{"Path":"/ipfs/k51qzi5uqu5dilgf7gorsh9vcqqq4myo6jd4zmqkuy9pxyxi5fua3uf7axph4y"}\n'

There is a /n appended to the end, which makes parsing the response as JSON annoying. i.e. you can't just do:

      const peerResponse = await fetch(`${kuboGateway}/api/v0/resolve/${peerId}`, { method: 'POST' })
      const peerJson = await peerResponse.json()
      return peerJson.Path

and instead need to do: const peerJson = JSON.parse(await peerResponse.text()).trim())