hirosystems / ordinals-api

Bitcoin Ordinals API
Apache License 2.0
199 stars 61 forks source link

Querying for inscriptions by >1 `mime_type` fails due to incorrect enconding #254

Open sabbyanandan opened 10 months ago

sabbyanandan commented 10 months ago

From Nima:

Hi, I'm trying to execute an api call as described on https://docs.hiro.so/ordinals/list-of-inscriptions

I'm adding two different mime type parameters in your API tester and the final call looks like this in the curl box: curl -L 'https://api.hiro.so/ordinals/v1/inscriptions?mime_type=image%2Fpng%2Cimage%2Fjpeg' \
-H 'Accept: application/json'

But when I execute the call I get this error:

{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "querystring/mime_type/0 must match pattern \"^\\w+\\/[-.\\w]+(?:\\+[-.\\w]+)?$\""
}

But I'm using your own API tester to do this and following all the instructions as far as I can tell.

How can we eliminate this error?

An example of a correctly encoded URL would be:

curl -L 'https://api.hiro.so/ordinals/v1/inscriptions?&mime_type=image%2Fsvg%2Bxml&mime_type=image%2Fapng' \ -H 'Accept: application/json'


The API demo panel in the Docs is not correctly encoding the special chars in the query param. But it could also be due to how the OpenAPI spec is designed. Therefore, I am opening the issue in the Ordinals API so we can verify it here first.

diwakergupta commented 10 months ago

Here's an example from the tests:

        const response3 = await fastify.inject({          method: 'GET',
          url: '/ordinals/v1/inscriptions?mime_type=image/png&mime_type=text/plain',
        });

Note the repeated mime_type -- I don't think the request is failing due to an encoding issue, it seems like it's failing because the 2nd mime type is provided without the mime_type argument.

sabbyanandan commented 10 months ago

@diwakergupta: Oh! Thanks for catching that. I blindly copied the URL from the dev console (through Ordinals Explorer) and included that in the example I listed in the description. I didn't pay close attention to the multiple mime_type pairs.

nima1981 commented 10 months ago

Here's an example from the tests:

        const response3 = await fastify.inject({          method: 'GET',
          url: '/ordinals/v1/inscriptions?mime_type=image/png&mime_type=text/plain',
        });

Note the repeated mime_type -- I don't think the request is failing due to an encoding issue, it seems like it's failing because the 2nd mime type is provided without the mime_type argument.

Correct, current API documentation states to use a comma to separate the values and the API tester implements this non functioning format.

See the line "Example: image/png,image/jpeg" at https://docs.hiro.so/ordinals/list-of-inscriptions

sabbyanandan commented 10 months ago

Aside from the OpenAPI spec and the related documentation issue, @nima1981 wonders (as a new feature request) whether the Ordinals API can support either of the following formats:

a: "comma separated" values b: a regex