Magento rest api: how to get orders by ids? - magento

How to get multiple orders filtered by Id from magento with help of rest api?
I tryed to use http://192.168.0.104:4422/magento/api/rest/orders?filter[1][attribute]=entity_id&filter[1][in]=1&filter[1][in]=3
but it returns me:
<magento_api>
<messages>
<error>
<data_item>
<code>401</code>
<message>oauth_problem=signature_invalid</message>
</data_item>
</error>
</messages>
</magento_api>
But if i use request with only one filter in parameter http://192.168.0.104:4422/magento/api/rest/orders?filter[1][attribute]=entity_id&filter[1][in]=1 - it works great.

For me the problem was in filters( I tried on 1.7.0.1). Looks like some magento versions have problems with filters. So you should use 1 filter, after that filter results in your code.

I found the answer in this blog post. In short, if you follow this structure (this was for my use case with a list of products):
http://magentohost.com/api/rest/products?filter[1][attribute]=entity_id&filter[1][in][1]=1&filter[1][in][2]=3
You'll be set! (this gets two products similar to above with ids 1 and 3). Notice the [1] and [2] after both of the [in]. I wish Magento had better documentation for this.

Try aggregating values.
complexFilter { key = "increment_id", value = new associativeEntity {key = "in", value = "1,2,3"} };

Related

Laravel Paginate not working with specific model or table

Paginate not working for specific model. with all Models, paginate is working fine except one specific model. Also tried with query builder.
$doubts = DB::table('users')->paginate(10);
dd($doubts->count());
//output: 10
$doubts = DB::table('doubts')->paginate();
dd($doubts->count());
//output: 0
$doubts = DB::table('doubts')->get();
dd($doubts->count());
//output: 8
Don't know what am I missing here. Please help.
Maybe I think you have to put
How many results you want to show per page
So if you want 8
Then I think it should be something like this
$doubts = DB::table('doubts')->paginate(8);
dd($doubts->count());
And if you are using pages Number under your data then you might need the query builder.
You should pass number argument inside paginate function.
Look at laravel pagination documentation
And make sure that DB::table('doubts')
Is returning collection
I thing you must add parameter in paginate(), to show how much data that show per page. You can read documentation in : https://laravel.com/docs/9.x/pagination#paginating-query-builder-results
https://laravel.com/docs/9.x/pagination#cursor-pagination
because you are not add parameter in paginate, it means not data that show every page.
$doubts = DB::table('doubts')->paginate(10);

Can anybody help me resolve the syntax?

if anybody can explain how this api work or take the paramaters when u search for a product . how this product status ,category id reflects .
seproduct/api/products?status.equals=Published&categoryId.in=59&name.contains=protein%20123&foodTypeId.in=1&allergenId.in=2&page=1&size=20&sort=sellingPrice,DESC
I can just guess because you don't provide the code or any documentation of the API.
This is the path:
seproduct/api/products?
Parameters
.equals and .in would translate to = and IN in SQL select.
contains probably to like '%<keywords>%'
status.equals=Published
categoryId.in=59
name.contains=protein%20123
foodTypeId.in=1
allergenId.in=2
Page and size are used for pagination and sort for sorting (DESC = descending)
page=1
size=20
sort=sellingPrice,DESC

Shopify Storefront API: Getting referenced variant with GraphQL

I'm using the Shopify Storefront API and Accentuate to try to get my hands on a specific variant, but it won't work for me.
THE SHORT VERSION: When I select a variant on the website, I get the url: (... url ...)?variant=31696763027492. How do I get my hands on these numbers after the = for the variant in GraphQL? It does not match the ID.
THE LONG VERSION...
In a product variant, I reference to a variant of another product (with Accentuate). What I need to get out is the variant that I am referencing to.
When I pull out the variant that is being referenced to in the product (as metafield, with GraphQL), I get this:
{
"key": "products_in_package",
"value": "pakke-produkt-gavepose:31696763027492"
}
My problem is the numbers after : in the value. I've found that these are the number that come after the URL of the product when selecting the variant on the "actual" Shopify website ((... url ...)?variant=31696763027492), but I can't see how I can use them, since I can't find these numbers on the actual variant through GraphQL.
It does not match the 'id' or anything else I could find on the variant. Neither can I include the numbers if I try to get productByHandle.
So, does anyone have any ideas on how I can I use it to get the actual product variant through GraphQL? Or ideas on what else I can do to connect a specific product variant to another product variant?
The storefront API and admin API return different format of Id
storefront API: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzQ3NjA3ODY1MDE3MDM="
Admin API: "gid://shopify/Product/4760786501703"
But there is a convert way between each other, use function atob
atob("Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzQ3NjA3ODY1MDE3MDM=") will get the Admin API Id
For NodeJS package: https://www.npmjs.com/package/atob
The variant ID and GraphQL variant ID is closely related.
Variant id - 31646396055604
GraphQL Variant id - gid://shopify/ProductVariant/31646396055604
The GraphQL ID is the same as the Variant id but you must add the string gid://shopify/ProductVariant/ before it.
So your GraphQL request will become like so:
{
productVariant(id:"gid://shopify/ProductVariant/31646396055604"){
title
product{
id
}
}
}
The problem is (or was) that those numbers are not what you get when you get the id from the product through GraphQL. You get a much longer id, like "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zMTY5NDA3MjQxNDI0NA==".
However, I figures out that using the btoa() JavaScript function on the id you mention (gid://shopify/ProductVariant/31646396055604), I got the long id that I get from the product itself. So problem solved!

GraphQL "not equal" operator?

I have a GraphQl API for listing a bunch of items, and I can query it perfectly etc.
But now I'd like to query for a subset of that list where one property can have 'all possible values except one specific one'.
For example, I want to query something like this:
{
items(status: !"Unwanted"){
id
}
}
That exclamation mark obviously doesn't work, but it illustrates what I am after.
Can't find any information about this online.
Does anybody know of a way to do this?
I would really hate having to enumerate all possible wanted values instead of just excluding the one unwanted value. This would be really bad design and is not scalable.
Thanks.
Use ne :
{
items(filter: {status: {ne: "Unwanted"}}){
id
}
}
If you can define the schema (implement the server) then you can add a second argument like statusExcept to the items field. Then in the resolve method check if status or statusExcept was set and deliver the items according to that.
It the server API is fixed there is afaik nothing that you can do except getting everything and filter on the client.
Using GraphQL version 4.3.2 the syntax has changed and you will need to use notIn
{
items(filter: {status: {notIn: "Unwanted"}}){
id
}
}

Getting Popular Searches In Magento

I want to display the top 10 searches on my Magento store. Magento already stores searches made on the store under Admin > Catalog > Search Terms, so it's just a matter of getting it into my view. Does anyone know which helper or function I can access to get this list?
You have a setPopularQueryFilter method in the class Mage_CatalogSearch_Model_Mysql4_Query_Collection, after that you only have to set a limit I guess :)
Without trying, it should be something like that :
$searchCollectino=Mage::getModel('catalogsearch/query')->getCollection()
->setPopularQueryFilter()
->setPageSize($limit);
If anyone needs the Magento 2 solution:
inject the class \Magento\Search\Model\Query in your constructor and then retrieve the collection like so:
$collection = $this->query->getSuggestCollection()
This will return a collection of most popular search terms sorted by the popularity.

Resources