Get the Cost column In the Shopify Platforw through API

Solved
New Member
6 0 0

Hello Team,

 

I work for Measured Inc, and we are the measurement partner to Faherty Brand.

 

We currently use the Shopify API for pulling necessary fields, and have a requirement to add in the “Cost” field into our API data reqCapture.PNGuest (last column in the attached screenshot).

 

Referring to the documentation below, we pulled in a report with the product_cost column from the API, but the Cost values in the API output does not align with that of the Shopify UI. (attached file has the last column as Product_Cost).

https://community.shopify.com/c/API-Announcements/New-cost-property-on-InventoryItem/td-p/461149

 

 

Could you please help us in getting the correct cost column from the API so as to align with cost from the UI ?

 

 

Regards

Siju Sahajan

Solutions Analyst

Measured, Inc.

mobile: 647.675.4110

0 Likes
New Member
6 0 0

Please the urls of the calls made for getting cost currently

 

Call 1 - "/admin/api/2019-04/orders.json "   -  We get the product id and variant id from this call at line item level

 

Call 2 - "/admin/api/2019-04/products.json" –  We make this call using the productid. Then once we receive json object, we extract inventory id using variant id.

 

Call3 - " /admin/api/2019-04/inventory_items/{inventory_item_id}.json"  We make this call using the inventory item id, and extract cost.

 

Is there something wrong with this approach ?

 

0 Likes
Community Manager
Community Manager
494 21 53

Hi @MeasuredInc,

 

Which report are you looking at in the screenshot you shared? In the reports section, the cost will only be taken into consideration if it was applied to the product at the time of the order it was sold. Is it possible this contributes to the mismatch?

 

The cost field you are pulling from the API is the same as the cost field being considered in our reporting. Based on this, the issue is likely in interpretation of the report within Shopify.

 

If you can share some additional context, details, and specific numbers that are mismatched, that would be helpful in pointing you in the right direction.

 

Cheers,

0 Likes
New Member
6 0 0

API Output.PNGHi,

 

The screenshot in the intial post is a sales over time report from the shopify UI, where I added the cost column from the column  drop down to the left in the UI. The report from the Shopify UI (Screenshot in first post), has a cost total of $102k.(Date Range Jun-03 to Jun-17)

 

When we pull the API report using the API calls I shared in my second post above for the same date range-, the cost totals to only - $21k

 

I am not able to pass you the file I pulled via the API here (cannot find an attach option). Have attached a screenshot of the output in .csv, you can see in column F, the product cost is not populating for all line item / prouct id combinations.

 

We use the 3 API Calls mentioned above and merge the report.

 

Regards

Siju.

0 Likes
Community Manager
Community Manager
494 21 53

Hi again,

 

I took a look at the report you are looking at in the shop in question, and compared the values for a handful of hours during the date range with the values obtained using the API calls you shared. I'm not seeing a discrepancy. For example, between 11pm and midnight on June 17th results in 274.01 when I look at the report, and adding the cost from line items in orders during that time using the API yields the same value.

 

It also looks like some products in the spreadsheet you shared don't have cost, when the actual inventory item associated with that product does.

 

Is it possible there is a flaw in the method your app is pulling those costs? Is the data you are using somewhat old?

 

Let me know if you see the same thing if you try to pull the data again.

0 Likes
New Member
6 0 0

Hi,

 

I am not able to see any "cost" field in line_items, can you please point out the field which you are referring to. Following is the JSON object received from the API:

 

line_items:[{
"id": 2606348501061,
"variant_id": 19551820742725,
"title": "Short-Sleeve Coast Shirt - Fishscale Batik",
"quantity": 1,
"sku": "MWU1914FIS",
"variant_title": "Fishscale Batik / XL",
"vendor": "Faherty",
"fulfillment_service": "manual",
"product_id": 2113188102213,
"requires_shipping": true,
"taxable": true,
"gift_card": false,
"name": "Short-Sleeve Coast Shirt - Fishscale Batik - Fishscale Batik / XL",
"variant_inventory_management": "shopify",
"properties": [],
"product_exists": true,
"fulfillable_quantity": 1,
"grams": 227,
"price": "138.00",
"total_discount": "0.00",
"fulfillment_status": null,
"pre_tax_price": "138.00",
"price_set": {
"shop_money": {
"amount": "138.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "138.00",
"currency_code": "USD"
}
},
"pre_tax_price_set": {
"shop_money": {
"amount": "138.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "138.00",
"currency_code": "USD"
}
},
"total_discount_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"discount_allocations": [],
"admin_graphql_api_id": "gid://shopify/LineItem/2606348501061",
"tax_lines": [
{
"title": "FL STATE TAX",
"price": "0.00",
"rate": 0,
"price_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
}
}
],
"origin_location": {
"id": 638156472389,
"country_code": "US",
"province_code": "NJ",
"name": "Faherty Brand",
"address1": "299 Thomas E. Dunn Memorial Hwy",
"address2": "",
"city": "Rutherford",
"zip": "07070"
}
}]

0 Likes
Highlighted

Success.

Community Manager
Community Manager
494 21 53

Sorry, I should have been more clear. When I said "the cost from line items in orders", I meant that I'm looking at the corresponding product and it's inventory item, where the cost is found. I followed the same flow you mentioned previously to get there ( fetch order -> product variant -> inventory item -> cost value).

0 Likes