Search and Replace via GraphQl
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Search and Replace via GraphQl
When I try to create products via GraphQL, everything works fine, the same goes for prices, categories, and so on. You use the code or label property that you want to use in the future. But now comes the part I don’t get: the design.
When I want to update the product via the same property, let’s say a product by code, I only get a duplicate error because the code is already in use.
So the intended way to update, let’s say, 100 products would be to:
1. Get the product IDs via a separate request.
2. Match the codes with the IDs in my script.
3. Create the products that do not exist via code.
4. Update products via ID.
5. Get all the price/other elements (and all the other options, every single attribute, different stock level per location, and so on).
6. Match all the many IDs I just got to the products and find the values that don’t exist yet to create them.
7. Insert the values that don’t exist via different properties like label and code, also insert the values of attributes I want to use into the attributes table. (not sure how smart it is to have something like like the cable length of a lamp as an attribute but i dont know any better way)
8. Update the existing values via the ID and add the attributes to the product via ID.
I’m sure I forgott a step along the way but it should be clear what i mean.
Why is it so complicated? Am I doing something wrong?
I don’t understand how this is intended to be used.
I know other GraphQL implementations allow for overwriting via the primary key element, and I think I remember that updating, for example, the price via the product update trough internal reference is also possible (though I might be wrong about that last point).
Does anyone have some guidance for this?
Best of days to you all
When I want to update the product via the same property, let’s say a product by code, I only get a duplicate error because the code is already in use.
So the intended way to update, let’s say, 100 products would be to:
1. Get the product IDs via a separate request.
2. Match the codes with the IDs in my script.
3. Create the products that do not exist via code.
4. Update products via ID.
5. Get all the price/other elements (and all the other options, every single attribute, different stock level per location, and so on).
6. Match all the many IDs I just got to the products and find the values that don’t exist yet to create them.
7. Insert the values that don’t exist via different properties like label and code, also insert the values of attributes I want to use into the attributes table. (not sure how smart it is to have something like like the cable length of a lamp as an attribute but i dont know any better way)
8. Update the existing values via the ID and add the attributes to the product via ID.
I’m sure I forgott a step along the way but it should be clear what i mean.
Why is it so complicated? Am I doing something wrong?
I don’t understand how this is intended to be used.
I know other GraphQL implementations allow for overwriting via the primary key element, and I think I remember that updating, for example, the price via the product update trough internal reference is also possible (though I might be wrong about that last point).
Does anyone have some guidance for this?
Best of days to you all
Re: Search and Replace via GraphQl
This is correct, the ID is the primary key element and the code alone isn't unique in Aimeos (only in combination with the siteid) so you need to fetch the products by code first to get their IDs.
This is not strictly necessary because you can also hand over all referenced items without IDs so they are treated as new but this will remove all referenced items first and then create the new ones again - even if there was only a single change in the product item. It's possible to use the GraphQL API that way but it's quite inefficient and will slow down updating the products.CojuAH wrote: ↑22 Oct 2024, 09:53 5. Get all the price/other elements (and all the other options, every single attribute, different stock level per location, and so on).
6. Match all the many IDs I just got to the products and find the values that don’t exist yet to create them.
7. Insert the values that don’t exist via different properties like label and code, also insert the values of attributes I want to use into the attributes table. (not sure how smart it is to have something like like the cable length of a lamp as an attribute but i dont know any better way)
8. Update the existing values via the ID and add the attributes to the product via ID.
The GraphQL API is intended for administrative purposes and heavily used in the Aimeos admin backend where the data is first fetched, then changed by the editor and finally written back with all the available IDs. It's not suited well for mass update of products from 3rd party systems and we recommend using the XML importer for that. The XML importer does all the matching internally so you don't have to care about that when generating the XML files. It's also capable of importing only changed products near-realtime.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,
