[SOLVED] Azure Blob List “Value for one of the query parameters specified in the request URI is invalid” when using API Management service

Question

This Content is from Stack Overflow. Question asked by Damo

I’m using API Management service to make a simple interface between a c# desktop application and a Azure Blob storage account.

API Management service is providing the authentication via a Subscription Key. This works fine for downloading blobs.

I also want to list the contents of an individual container / folder (prefix) using the same method.

I’ve tested the following HTTP call outside the API Management service, it works correctly.

https://<account>.blob.core.windows.net/files?restype=directory&comp=list&prefix=globalpackages/1.0

When I use this in API Management service, I’m returned an error:

<Error>
    <Code>InvalidQueryParameterValue</Code>
    <Message>Value for one of the query parameters specified in the request URI is invalid.
RequestId:917b0aa8-101e-006b-0709-8e85b0000000
Time:2022-07-02T11:47:29.0834806Z</Message>
    <QueryParameterName>comp</QueryParameterName>
    <QueryParameterValue>list</QueryParameterValue>
    <Reason />
</Error>

My processing rules:

<policies>
    <inbound>
        <base />          
        <set-header name="Ocp-Apim-Subscription-Key" exists-action="delete" />
        <set-header name="Sec-Fetch-Site" exists-action="delete" />
        <set-header name="Sec-Fetch-Mode" exists-action="delete" />
        <set-header name="Sec-Fetch-Dest" exists-action="delete" />
        <set-header name="Accept" exists-action="delete" />
        <set-header name="Accept-Encoding" exists-action="delete" />
        <set-header name="Referer" exists-action="delete" />
        <set-header name="X-Forwarded-For" exists-action="delete" />
        <set-header name="x-ms-version" exists-action="override">
            <value>@{string version = "2017-11-09"; return version;}</value>
        </set-header>
        <set-backend-service base-url="@{
return String.Format("https://<storageaccount>.blob.core.windows.net/files?restype=directory&comp=list&prefix=globalpackages/1.0");
}" />
        <authentication-managed-identity resource="https://storage.azure.com/" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

what am I doing wrong?

Solution

Based on the documentation available here, the query parameter should be restype=container instead of restype=directory if you need to list blobs inside a blob container.

Once you make this change, you should be able to list the blobs.

Answered by Gaurav Mantri, Content is distributed under the terms of CC BY-SA 4.0.

people found this article helpful. What about you?