Publishing IPFS object to IPNS works using CLI but not HTTP API

I am trying to publish an IPNS name (i.e. publish an IPFS object to IPNS) using the HTTP API, but I keep getting an error. Documentation link

curl -X POST "http://127.0.0.1:5001/api/v0/name/publish?arg=’/ipfs/QmZCDSGV7PRJjRb2PFyopKzsU79LgmPo7AziaB89XFXyP3’"

{“Message”:“invalid path “’/ipfs/QmZCDSGV7PRJjRb2PFyopKzsU79LgmPo7AziaB89XFXyP3’”: cid too short”,“Code”:0,“Type”:“error”}

Tried modifying the argument by removing the ‘/ipfs/’ part, but get a different error now.

curl -X POST "http://127.0.0.1:5001/api/v0/name/publish?arg=‘QmZCDSGV7PRJjRb2PFyopKzsU79LgmPo7AziaB89XFXyP3’"

{“Message”:“invalid path “‘QmZCDSGV7PRJjRb2PFyopKzsU79LgmPo7AziaB89XFXyP3’”: selected encoding not supported”,“Code”:0,“Type”:“error”}

When I use the CLI it works just fine.

ipfs name publish /ipfs/QmZCDSGV7PRJjRb2PFyopKzsU79LgmPo7AziaB89XFXyP3

Published to k51qzi5uqu5dmhtzin0shoviap3jncuk82n0hui6kr1juhhwbigr0535kdlk11: /ipfs/QmZCDSGV7PRJjRb2PFyopKzsU79LgmPo7AziaB89XFXyP3

Couldn’t find anybody talking about this anywhere when I looked online. Any solutions are appreciated!!

Thank you!!

Quick guess: when creating a URL by hand, do not put single quotes (') around the CID.

@lidel But it says to give it as a string in the documentation

Do you have any other ideas regarding why it may not be working?

A string doesn’t mean “put quotes arround it”.
You need to follow the the url-encoding specs.
Which should be (I belive):

curl -X POST "http://127.0.0.1:5001/api/v0/name/publish?arg=QmZCDSGV7PRJjRb2PFyopKzsU79LgmPo7AziaB89XFXyP3"

Oh :sweat_smile: oops
It’s working now! Thank you!

1 Like

BTW, when the spec says “string”, that to say about how URL encode special characters.
For example, if you wanted to pin the CID Qm&&& (which isn’t a valid CID but anyway let’s assume it is).
You would need to escape the & because they are control characters (they indicate the next field in an GET sequence).
So you would use: http://127.0.0.1:5001/api/v0/name/publish?arg=Qm%26%26%26.

To automate that process you have thoses functions in python for example:

import urllib
print(urllib.urlencode({"arg": "Qm&&&"})) # -> arg=Qm%26%26%26
1 Like

Okay, got it :+1: Thanks