question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Query string for this HTTP request type is an invalid URL." when executing a stored procedure using POST

See original GitHub issue

When calling a stored procedure, also passing parameters, using the POST method, I get the following error:

{
  "error": {
    "code": "BadRequest",
    "message": "Query string for this HTTP request type is an invalid URL.",
    "status": 400
  }
}

everything works fine if I use the GET method. I haven’t tested with other HTTP methods, but I suspect I’ll get the same error.

This is the error message I can see in the log:

Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
      Executing endpoint 'Azure.DataApiBuilder.Service.Controllers.RestController.Insert (Azure.DataApiBuilder.Service)'
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
      Route matched with {action = "Insert", controller = "Rest"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] Insert(System.String) on controller Azure.DataApiBuilder.Service.Controllers.RestController (Azure.DataApiBuilder.Service).   
fail: Azure.DataApiBuilder.Service.Controllers.RestController[0]
      Query string for this HTTP request type is an invalid URL.
fail: Azure.DataApiBuilder.Service.Controllers.RestController[0]
         at Azure.DataApiBuilder.Service.Services.RequestValidator.ValidateInsertRequest(String queryString, String requestBody)
         at Azure.DataApiBuilder.Service.Services.RestService.PopulateStoredProcedureContext(Operation operationType, DatabaseObject dbObject, String entityName, String queryString, String primaryKeyRoute, String requestBody, RestRequestContext& context)
         at Azure.DataApiBuilder.Service.Services.RestService.ExecuteAsync(String entityName, Operation operationType, String primaryKeyRoute)
         at Azure.DataApiBuilder.Service.Controllers.RestController.HandleOperation(String route, Operation operationType)

Issue Analytics

  • State:closed
  • Created 7 months ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
yorekcommented, Feb 8, 2023

May bad, I didn’t remember that. Documentation doesn’t mention it (https://github.com/Azure/data-api-builder/blob/main/docs/views-and-stored-procedures.md#rest-support-for-stored-procedures) so it needs to be added as now only mention the following:

If the stored procedure accepts parameters, those can be passed in the URL query string when calling the REST endpoint. For example:

which is incomplete

1reaction
seantleonardcommented, Feb 7, 2023

@yorek, this is by design from the stored procedure specification

[REST] [parameters can either be fixed as above or passed at runtime through] request body for POST, PUT, PATCH, DELETE

For POST-ing to GetCowrittenBooksByAuthor you’d have to add a JSON request body with your desired parameters/values: URL: [POST] /api/cowrittenBooksByAuthor Body:

{
    "author": "*",
    "searchType": "s"
}

https://github.com/Azure/data-api-builder/blob/daf7dd8bf6737266b32b3eb86fb926dacd92f8a8/docs/internals/StoredProcedureDesignDoc.md?plain=1#L35-L38

Read more comments on GitHub >

github_iconTop Results From Across the Web

Calling a stored procedure with Entity Framework Core ...
When I debug, I get the following error: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An unhandled exception has ...
Read more >
Maintenance Plan Wizard generates invalid script?
In this case, the "Maintenance Cleanup Task" was missing the path (the wizard does not seem to validate whether you enter one).
Read more >
Invalid URL Path Error - OutSystems 11 Documentation
The Invalid URL Path error is issued in the following situations: Message: 'URL Path' property must start with '/'. Cause: The specified URL...
Read more >
SQL Queries - EF Core
Using SQL queries in Entity Framework Core. ... SQL queries can be used to execute a stored procedure which returns entity data:.
Read more >
How to implement error handling in SQL Server
This article explains how to implement SQL error handling using the SQL server try-catch statement and what can be done in general when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found