Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax call to 'api/queries/{name}' fails #5533

Closed
sht1rlitz opened this issue Feb 12, 2020 · 5 comments
Closed

Ajax call to 'api/queries/{name}' fails #5533

sht1rlitz opened this issue Feb 12, 2020 · 5 comments
Milestone

Comments

@sht1rlitz
Copy link

Hello everyone,

I'm currently trying to receive query results using an AJAX call:

var products = $.ajax({
            type: "POST",
            url: "api/queries/ProductList",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: JSON.stringify({ parameters: { from: 0, size: 8 }}),
        });

but it fails with "System.InvalidCastException: Null object cannot be converted to a value type."

This happens because Task<IActionResult> Query( string name, string parameters) always get parameters equals to null and instantiate an empty Dictionary.

LuceneQueryService tries to get the value at the var size = sizeProperty?.Value<int>() ?? 50; line and fails.

All the required permissions for Queries are granted.
Could someone point me on what I'm doing wrong, please?

@Skrypt
Copy link
Contributor

Skrypt commented Feb 12, 2020

JSON.stringify({ from: 0, size: 8 })

@sht1rlitz
Copy link
Author

Hi Skrypt,
I've already tried this case too, but result unfortunately is the same.

@sht1rlitz
Copy link
Author

Hasn't anyone faced this issue? I guess requesting query result via ajax is a widespread scenario.
Perhaps, it is not a bug, but rather a documentation gap.

@sht1rlitz
Copy link
Author

Hello everyone,

I've figured out, that current implementation only allows querying results with GET, like

var products = $.getJSON( "api/queries/ProductList?parameters={from:0,size:8}");

I'm really confused at this moment as I've never seen passing objects into GET query.
Moreover, current documentation assures me that both methods are supported

Verbs: POST and GET

So my assumptions were:

  1. If my Query isn't parameterized I'm supposed to use GET-request
  2. If I have a complex object as a Query parameter, I need to use POST instead

@sebastienros
Copy link
Member

I've never seen passing objects into GET query

For instance GraphQL supports GETs too, like this.

It would be ok to support POST though and read the parameters from the body (like GraphQL does it too)

@sebastienros sebastienros added this to the 1.0.x milestone Feb 27, 2020
emrahtokalak pushed a commit to emrahtokalak/OrchardCore that referenced this issue Jun 12, 2023
emrahtokalak pushed a commit to emrahtokalak/OrchardCore that referenced this issue Aug 5, 2023
sebastienros added a commit to emrahtokalak/OrchardCore that referenced this issue Feb 2, 2024
urbanit pushed a commit to urbanit/OrchardCore that referenced this issue Mar 18, 2024
@MikeAlhayek MikeAlhayek modified the milestones: 2.x, 2.0 Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants