Shopify Create Order API - shopify

I used the Shopify API to create an order using my product's variantID.
For some reason, line_items in orders created using the API always have "vendor":"null". Whereas orders for the same variant created via the store returns the correct vendor.
Am I doing anything wrong?
URL: https://xxyy.myshopify.com/admin/orders.json
{ "order": {
"email": "ken#xxyy.com",
"fulfillment_status": "unfulfilled" ,
"send_receipt": true,
"send_fulfillment_receipt": false,
"line_items": [{
"variant_id": 3866750123,
"quantity": 1
}]
}
}

I get that sometimes too and it is truly crappy. If you create a line item using the API it seems you need to provide not only the product and variant ID, but also the vendor, as even if it exists in the product, that does not get picked up in the order creation process. A lot of Apps screw this up. Which screws up other Apps expecting good orders. And a it seems to me a good order should have the product vendor field set.

Related

How to get the products in a category thats based on Dynamic Product Groups from the shopware API

I have a high volume shop with a lot of products and categories.
The products are seasonal, so a lot of new products are added.
Because of this, dynamic product groups are perfect. We set conditions and add the group to the category.
Right now i'm trying to get all the products of the category in the api's (both backend and store), but i dont get any product back. I do get a streamId back in the store-api https://localhost//store-api/product-listing/9cf2c65bd7084144aa4d4a35bb3f568e But there is no endpoint i can call for the streamId.
Next to that, the breadcrumbs are also missing on the front-end.
What is the best way to get a the products from a category back in the API?
Thanks!
If you do have the id of the product_stream you can filter product entities by them having that id as part of their streamIds:
// POST /api/search-ids/product
{
"page": 1,
"limit": 500,
"filter": [
{
"type": "equalsAny",
"field": "streamIds",
"value": [
"65103ca79e1e4e3ba846f551fbb1cb36" // your product stream id
]
}
]
}

Item level tracking in Shopify

Could you please specify, what is the correct way to track the quantity of the variants of items in stock?
I see that products/update webhook shows the quantity, but I'm not sure if it fires when an item is purchased (and its quantity reduces by one), and in case of inventory_items/update there's no quantity information (though it seems I can thract it using InventoryLevel API call), but I'm not sure if this notification launches after item purchase.
Short answer: Both products/update and inventory_levels/update are fired when an item is purchased.
The request body of products/update looks something like this:
{
"id": 123,
"variants": [
{
"id": 456,
"product_id": 123,
"inventory_quantity": 99
}
]
}
inventory_quantity is the updated stock of the item that has just been purchased.
On the other hand, the request body of inventory_levels/update looks something like this:
{
"inventory_item_id": 987,
"available": 99
}
So both webhook topics give you access to the data you need. In the end it depends on your specific use case which of those two topics to use.

Selecting the latest document for each "Group"

I am using Azure Cosmos DB SQL API to try to achieve the following;
We have device data stored within a collection and would love to retrieve the latest event data per device serial effectively without having to do N queries for each device separately.
SELECT *
FROM c
WHERE c.serial IN ('V55555555','synap-aim-g1') ORDER BY c.EventEnqueuedUtcTime DESC
Im assuming I would need to use Group By - https://learn.microsoft.com/en-us/azure/cosmos-db/sql-query-group-by
Any assistance would be greatly appreciated
Rough example of data :
[
{
"temperature": 25.22063251827873,
"humidity": 71.54208429695204,
"serial": "V55555555",
"testid": 1,
"location": {
"type": "Point",
"coordinates": [
30.843687,
-29.789895
]
},
"EventProcessedUtcTime": "2020-09-07T12:04:34.5861918Z",
"PartitionId": 0,
"EventEnqueuedUtcTime": "2020-09-07T12:04:34.4700000Z",
"IoTHub": {
"MessageId": null,
"CorrelationId": null,
"ConnectionDeviceId": "V55555555",
"ConnectionDeviceGenerationId": "637323979596346475",
"EnqueuedTime": "2020-09-07T12:04:34.0000000"
},
"Name": "admin",
"id": "6dac491e-1f28-450d-bf97-3a15a0efaad8",
"_rid": "i2UhAI7ofAo3AQAAAAAAAA==",
"_self": "dbs/i2UhAA==/colls/i2UhAI7ofAo=/docs/i2UhAI7ofAo3AQAAAAAAAA==/",
"_etag": "\"430131c1-0000-0100-0000-5f5621d80000\"",
"_attachments": "attachments/",
"_ts": 1599480280
}
]
UPDATE:
So doing the following returns the correct data but sadly you can only return data thats inside your group by or an aggregate function (i.e. cant do select *)
SELECT c.serial, MAX(c.EventProcessedUtcTime)
FROM c
WHERE c.serial IN ('V55555555','synap-aim-g1')
GROUP BY c.serial
[
{
"serial": "synap-aim-g1",
"$1": "2020-09-09T06:29:42.6812629Z"
},
{
"serial": "V55555555",
"$1": "2020-09-07T12:04:34.5861918Z"
}
]
Thanks for #AnuragSharma-MSFT's help:
I am afraid there is no direct way to achieve it using a query in
cosmos db. However you can refer to below link for the same topic. If
you are using any sdk, this would help in achieving the desired
functionality: https://learn.microsoft.com/en-us/answers/questions/38454/index.html
We're glad that you resolved it in this way, thanks for sharing the update:
So doing the following returns the correct data but sadly you can only return data thats inside your group by or an aggregate function (i.e. cant do select *)
SELECT c.serial, MAX(c.EventProcessedUtcTime)
FROM c
WHERE c.serial IN ('V55555555','synap-aim-g1')
GROUP BY c.serial
[
{
"serial": "synap-aim-g1",
"$1": "2020-09-09T06:29:42.6812629Z"
},
{
"serial": "V55555555",
"$1": "2020-09-07T12:04:34.5861918Z"
}
]
If the question is really about an efficient approach to this particular query scenario, we can consider denormalization in cases where the query language itself doesn't offer an efficient solution. This guide on partitioning and modeling has a relevant section on getting the latest items in a feed.
We just need to get the 100 most recent posts, without the need to
paginate through the entire data set.
So to optimize this last request, we introduce a third container to
our design, entirely dedicated to serving this request. We denormalize
our posts to that new feed container.
Following this approach, you could create a "Feed" or "LatestEvent" container dedicated to the "latest" query which uses the device serial as id and having a single partition key in order to guarantee that there is only one (the most recent) event item per device, and that it can be fetched by the device serial or listed with least possible cost using a simple query:
SELECT *
FROM c
WHERE c.serial IN ('V55555555','synap-aim-g1')
The change feed could be used to upsert the latest event, such that the latest event is created/overwritten in the "LatestEvent" container as its source item is created in the main.

Access Product Variant Price with Stencil

With the legacy API, I can obtain product variant prices for productId 100 with the following:
https://something.com/api/v2/products/100/skus.json
But in the Stencil documentation for Product, there is no price property for a product attribute SKU, and the available properties that are available are limited vs the legacy API.
With product:
"values": [
{
"label": "Hardcover",
"id": 98,
"data": "Hardcover",
"selected": false
},
{
"label": "Paperback",
"id": 100,
"data": "Paperback",
"selected": false
}
],
From what I can gather, the variant pricing is only available via cart.items, but I need to display the prices before the user places an item in the cart.
Is there a way to get product variant pricing/info without using the cart.items object? Thanks!
I'm not aware of a way to do this via a stencil object.
On the product detail page I check if a product has_options, then make ajax calls to the variant URLs to get their prices to create a price range before the user selects their variants. This is pretty necessary when the vendor has huge price differences in variants.
ex.) "From $49.99 - $499.99" instead of "$49.99" default functionality.
I don't have a resolution for category pages as it doesn't make sense to make AJAX requests for each variant of each item on the category page on load. Once Stencil adds support for custom fields on the category page, you could add the child's prices to a parent SKUs custom field and perform some logic for whatever your trying to accomplish.
I don't know when custom fields will be available on the category page but I know they are working on it.

What are the specific id's required for the fulfillment cancel call in the shopify API?

I've written an automated system to automatically fulfill items in shopify via the API from data received from a fulfillment center but would like to build a tool to "undo" fulfillment should there be a problem but I can't seem to get the API to respond and the documentation is fuzzy as to which id's are required..
I assume the first #id is the order id and the second the item but I've tried all the id's from the order/fulfillment (line item ids, item_id, etc) and I'm still getting a {"errors":"Not Found"} from POST CURL call.
Am I using the wrong id? or is there some other reason work?
Here's the url Im hitting:
https://{API_KEY}:{API_PASS}#{my_store}.myshopify.com/admin/orders/{order_id}/fulfillments/{some_id?}/cancel.json
The first ID is the order ID, as defined in the order_id parameter on the fulfillment.
The second ID is the fulfillment ID, which is defined in the id parameter on the fulfillment.
Assuming you have a fulfillment that looks like this:
"fulfillment": {
"created_at": "2012-10-16T11:31:17-04:00",
"id": 255858046,
"order_id": 450789469,
"service": "manual",
"status": "pending",
"tracking_company": null,
"tracking_number": "1Z2345",
"tracking_url": "http://www.google.com/search?q=1Z2345",
"updated_at": "2012-10-16T11:31:17-04:00",
"receipt": {
"testcase": true,
"authorization": "123456"
}
}
Your POST URL should look like this:
/admin/orders/450789469/fulfillments/255858046/cancel.json