WooCommerce Rest API JSON formate Complex implementation in Swift - swift5

I want to get the products for each categories.For example in Swift5, tableview have multiple cells and cells contains, category name(FF) and collection view (all products for FF).But the JSON formate is so mix of categories in WooCommerce, how can I get the products for each categories. I am hitting this Woocommerece API https://www.example.com/wp-json/wc/v1/products?consumer_key=XXX&consumer_secret=XXX

I think you should pass a parameter in the URL something like that: filter[category]=Bedroom

Related

How do I query a GitHub Project V2 Item Order by Custom Field from GraphQL?

How do I get the order of items in a board view column from the API? I found the sortBy object in the ProjectV2 views, but I'm struggling querying the items ordered by fieldValue (position?).
Would you mind helping me construct a query for the JSON equivalent of the data in the picture, please?

WooCommerce rest api include parameter not fetching variation with variable product

https://example.com/wp-json/wc/v3/products/10 product type=variable and it is working fine
https://example.com/wp-json/wc/v3/products/11 product type=variation and it is working fine
But it fetch only one product (with id 10) using include parameter like
https://example.com/wp-json/wc/v3/products?include=10,11
I need help so that i can fetch 2 or more products (any type) in one API call
Do you need to retrieve all the products in woo commerce. If try with this call " /wp-json/wc/v3/products"
A bit late but maybe someone has the same problem still
The include parameter should be array and as this thread explains How to pass an array within a query string?
you should send your parameters as this
https://example.com/wp-json/wc/v3/products?include[]=10&include[]=11

RESTful API desgin: retrieve number of items in category

I want to create a REST API with items in categories and list all categories alongside its number of items.
Schemas:
Category {id, name}
Item {id, name, categoryId}
Endpoints:
GET /categories/list
GET /categories/<id>
PUT /categories/<id>
GET /items/list[?category=<categoryId>]
GET /items/<id>
To update a category I take what I get from GET /categories/<id>, modify the JSON object and PUT it back.
So far so good.
My question is if there are one ore more best practices to retrieve the item count?
I can think of a few ways to do this:
Fire a GET /items/list?category=<categoryId> for each category, counting the resulting items.
Taking the count from a X-total-count or content range header or a total_count field returned from the endpoint will avoid having to actually load all items.
Add an item_count field to the resulting category JSON objects.
How should this read only field be handled for PUTs? Make the backend ignore it? Manually unset it?
Create a dedicated endpoint /categories/item_counts that returns a list of categories with each number of items.
I like option number 2 (e.g. the wordpress API does it this way) because it does not need extra requests. But I really dislike the idea of having a different object structure for the GET and PUT requests.
REST is really about representation of objects. Category doesn't have a count as it's a single object. Item doesn't have a count either for the same reason. Count is more like RPC where you tell the service to compute something.
GET /items/list[?category=<categoryId>]
is like RPC, passing the category parameter to the list method. Staying in that idiom, you could "chain" the methods to get the total count of items in the specified category:
GET /items/list/count[?category=<categoryId>]
although I'd use path parameters instead:
GET /items/list/<category_id>/count
but list is implied so you could remove it:
GET /items/<category_id>/count
It's straying a bit from "pure" REST but it keeps your actual REST objects clean, as you say, keeping total_count our of your Category objects.
I'm assuming you sometimes need the count but not all the Items otherwise you wouldn't need to ask the API for the count, you'd just count them yourself in the client. That suggests another option:
GET /categories/<id>/count
{
"total_count": 10
}
which fits better with the use case of finding out how many Items are in a Category.

Get more product field value in Algolia json data

We are using Algolia extension for Magento 2. We added 2-3 field in the products, so we want to show the value of those fields on instant search result page. As we checking the view/frontend/templates/instant/hit.phtml is in use, we want to add the custom attributes to the JSON data so we can fetch those attributes value and show in listing page.
First you have to add new fields to Algolia product index if not already added. You can use one of the custom backend events. e.g. algolia_after_create_product_object
Once your fields are indexed properly (verify from Algolia account console), you should be able to get those in hit.phtml

Rest API: How should the filter params send to API in case query based on nested resource

I have two entities Properties and Bookings.
I need to know the URL structure in case I'm filtering the properties base on query on bookings.
In my case I need to get the properties which are free (not occupied) at specific date.
Can it be
api/properties/free/{date}
Or
api/properties/bookings?bookingDate!='1-1-2017'
Or
api/properties?bookingDate!='1-1-2017'
it seems for me that the last one is the more appropriate but the filter is on the bookings not on the properties which is not obvious.
The Facebook Graph API has a interesting way of doing nested queries by using a strategy of fields filter.
The fields filter it´s a way of filter specific fields or nested fields of a rouserce. They also create a standard way to inform functions for every selected field like: limit or equal.
Your request would be something like this:
GET /api/properties?fields=bookings{bookingDate.notEqual('1-1-2017')}
For more information about Facebook´s GraphAPI:
https://developers.facebook.com/docs/graph-api/overview/