How to Use Cube.js API with .NET Core Application? Facing "Query Param is Required" Error

NALB 71 Reputation points
2025-01-12T00:32:58.51+00:00

Hello,

I am trying to integrate the Cube.js API into my .NET Core application. My goal is to fetch data from Cube.js using a custom query. However, I keep encountering an error and can't seem to get the integration working.

Here’s the method I implemented based on an example I found:

public async Task<string> GetRoomOccupancyDataAsync()
{
    var query = new
    {
        measures = new[] { "room_occupancies.count" },
       dimensions = new[]
       {
           "room_occupancies.roomtype",
           "room_occupancies.checkindate"
        },
        limit = 10
    };
    var jsonQuery = JsonSerializer.Serialize(query);
    var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:4000/cubejs-api/v1/load")
    {
        Content = new StringContent(jsonQuery, Encoding.UTF8, "application/json")
    };
    var response = await _httpClient.SendAsync(request);
    if (!response.IsSuccessStatusCode)
    {
        var errorContent = await response.Content.ReadAsStringAsync();
        throw new HttpRequestException($"Error: {response.StatusCode}, Details: {errorContent}");
    }
    return await response.Content.ReadAsStringAsync();
}

and the response

{`` ``"error":`` ``"Query param is required",`` ``"stack":`` ``"Error: Query param is required\n at ApiGateway.parseQueryParam (/cube/node_modules/@cubejs-backend/api-gateway/src/gateway.ts:2000:13)\n at ApiGateway.load (/cube/node_modules/@cubejs-backend/api-gateway/src/gateway.ts:1699:20)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\n at /cube/node_modules/@cubejs-backend/api-gateway/src/gateway.ts:305:7",`` ``"requestId":`` ``"5573e971-9aa4-4d8c-a302-5fe6366f8885-span-1"`` ``}
.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,053 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,740 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ruikai Feng - MSFT 2,591 Reputation points Microsoft Vendor
    2025-01-13T05:25:52.1633333+00:00

    Accroding to the document,the data format should be like:'{"query": {"measures":["users.count"]}}'

    modify

    var query = new 
    {
      measures = new[] { "room_occupancies.count" },
      dimensions = new[] { "room_occupancies.roomtype", "room_occupancies.checkindate" }, 
      limit = 10 
    };
    
    var jsonQuery = JsonSerializer.Serialize(query);
    

    to

    var query = new
    {
        query = new
        {
            measures = new[] { "room_occupancies.count" },
            dimensions = new[]
           {
               "room_occupancies.roomtype",
               "room_occupancies.checkindate"
            },
            limit = 10
        }
        
    };
    var jsonQuery = JsonSerializer.Serialize(query);
    
    
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Ruikai Feng


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.