0

We use JSON:API specification on our API. Currently having issues with formatting the filter params to the specification using Flurl in C#.

Example:

        var url = await Helpers.GetAPIPath()
           .AppendPathSegment("orders")
           .WithOAuthBearerToken(Helpers.GetAPIToken())
           .SetQueryParams(new {
               filters = "[work_orders]=true,[status]=pending_approval",
               include = "shipping-address,inventory-items.part"
           }).GetAsync();

This produces /orders?filters[work_orders]=true,[status]=pending_approval&include=shipping-address,inventory-items.part

Here's documentation on a JSON:API request with multiple filters https://jsonapi.org/recommendations/#filtering

How can I structure the filters similar to filter[work_orders]=true,filter[status]=pending_approval for the JSON:API specification?

Any help is much appreciated!

1
  • The correct link would be ?filter[work_orders]=true&filter[status]=pending_approval. Using a & to separate query params and not ,. Commented Oct 30, 2020 at 9:43

1 Answer 1

1

This snippet was able to achieve the correct filtering parameters. Not sure if there's a cleaner way to implement this but so far it's working!

         var orderResponse = await Helpers.GetAPIPath()
            .AppendPathSegment("orders")
            .WithOAuthBearerToken(Helpers.GetAPIToken())
            .SetQueryParam("filter[work_orders]=true")
            .SetQueryParam("filter[status]=pending_approval")
            .SetQueryParams(new {
                include = "shipping-address,inventory-items.part",
            }).GetAsync();
Sign up to request clarification or add additional context in comments.

1 Comment

Yep, this works. The problem with the object syntax is the [ and ] characters aren't legal in a C# property name. Flurl will accept a dictionary object (with string keys) here, or the way you've done it here works too, but you'd typically separate name and value, i.e. SetQueryParam("filter[work_orders]", "true").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.