I've stubled upon an issue for updating order line items' metadata via WooCommerce REST API using node.js.
I've been following these steps for updating orders (and was succesful with some fields):
https://woocommerce.github.io/woocommerce-rest-api-docs/#update-an-order
Now, what I would like to achieve is changing the number of shipped line items of an order. Something I would normally use the partial orders WC plugin in the wordpress UI.
Below, you can find a screenshot of a line item I get from WC using the orders API call. The last element of the meta_data array has key 'shipped' and it contains an array with one object, stating that one (out of two ordered items) had been shipped:
"line_items": [{
"id": 1937,
"name": "Maya",
"product_id": 1271,
"variation_id": 1272,
"quantity": 2,
"tax_class": "",
"subtotal": "140.00",
"subtotal_tax": "0.00",
"total": "140.00",
"total_tax": "0.00",
"taxes": [],
"meta_data": [{
"id": 21637,
"key": "pa_product-color",
"value": "beige"
}, {
"id": 21638,
"key": "pa_shoe-size",
"value": "42"
}, {
"id": 21639,
"key": "pa_shoe-width",
"value": "wide"
}, {
"id": 21640,
"key": "shipped",
"value": [{
"qty": 1,
"date": "Nov 21, 2017"
}
]
}
],
"sku": "2522BE42W",
"price": 70
},
As you can see, the value of the key 'shipped' is an object. When I ty to send it (back) to WC, I get an error saying:
"data":{"status":400,"params":{"line_items":"line_items[0][meta_data][3][value] is not of type string."}}}
When I try to send the value as a string, i.e.
lineItems[0].meta_data = [{key:"shipped", value: "[{qty:'2'}]" }]
I get no errors, but WC treats this as string, not as an object and doesn't update the shipment qty in the DB the way I intended (it only pulls the shipped quantity down to 0 instead):
{
"id": 21640,
"key": "shipped",
"value": "[{qty:'2'}]"
}
Any insights or ideas - how could I modify the shipped quantity of line items via the WC API?
So, apparently there was a bug in WP 4.9 version, which was fixed recently in the following commit:
https://github.com/woocommerce/woocommerce/pull/17849
It concerns REST API schema and after merging the fix to WooCommerce, the problems disappear and now I am able to send the data as an object.
More on the topic can be found here:
https://github.com/woocommerce/wc-api-dev/pull/74
Related
Our onlineshop recently has issues getting the correct category orders over to our stock management system via API.
Whenever we test the API Calls in Postman with:
wp-json/wc/v3/products/categories?page=1
we get a completely random category order output like this:
First call:
[
{
"id": 5179,
"name": "Redmi Note 2022",
"slug": "redmi-note-2022",
"parent": 3054,
Second call:
[
{
"id": 5181,
"name": "Displayeinheit",
"slug": "displayeinheit-redmi-note-2022",
"parent": 5179,
Any advice how we can resolve this issue?
The issue has been resolved:
The problem was caused by the plugin:
https://wordpress.org/plugins/taxonomy-terms-order/
I am using curl with REST to access Smartshets in my C# running on WIN CE. My application is supposed to dump some data on smartsheet periodically.
Before I write to a sheet, I would like to know the total row count in the sheet so that I don't exceed 5000 rows per sheet.
I am looking for an API that would return just row count given the sheet id?
Currently using below API which returns the entire sheet data and takes very long to fetch and format.
curl https://api.smartsheet.com/2.0/sheets/{sheetId}
with data of upto 5000 rows pr sheet, it takes very long to fetch and format below response to determine the available rows:
{
"id": 4583173393803140,
"name": "sheet 1",
"version": 6,
"totalRowCount": 240,
"accessLevel": "OWNER",
"effectiveAttachmentOptions": [
"EVERNOTE",
"GOOGLE_DRIVE",
"EGNYTE",
"FILE",
"ONEDRIVE",
"DROPBOX",
"BOX_COM"
],
"readOnly": true,
"ganttEnabled": true,
"dependenciesEnabled": true,
"resourceManagementEnabled": true,
"cellImageUploadEnabled": true,
"userSettings": {
"criticalPathEnabled": false,
"displaySummaryTasks": true
},
"userPermissions": {
"summaryPermissions": "ADMIN"
},
"workspace": {
"id": 825898975642500,
"name": "New Workspace"
},
"projectSettings": {
"workingDays": [
"MONDAY",
"TUESDAY",
"WEDNESDAY"
],
"nonWorkingDays": [],
"lengthOfDay": 8
},
"hasSummaryFields": false,
"permalink": "https://app.smartsheet.com/b/home?lx=pWNSDH9itjBXxBzFmyf-5w",
"createdAt": "2018-09-24T20:27:57Z",
"modifiedAt": "2018-09-26T20:45:08Z",
"columns": [
{
"id": 4583173393803140,
"version": 0,
"index": 0,
"primary": true,
"title": "Primary Column",
"type": "TEXT_NUMBER",
"validation": false
},
{
"id": 2331373580117892,
"version": 0,
"index": 1,
"options": [
"new",
"in progress",
"completed"
],
"title": "status",
"type": "PICKLIST",
"validation": true
}
],
"rows": Array[4962]....
}
Any help will b greatly appreciated.enter code here
There isn't a request to specifically return the number of rows on a Sheet. But, with any GET /sheets/{sheetId} operation the resulting Sheet object returned will have a top level totalRowCount attribute on it. So, you don't have to GET the sheet and count the objects in the rows array. Instead you can look to the totalRowCount attribute and the value there to know how many rows are currently on the sheet.
If you are concerned about pulling down all of the Sheet data you can use paging to keep from getting all of the data returned. Doing a GET /sheets/{sheetId}?pageSize=1 will give you the Sheet object with only the first row of data to help make the payload smaller. The totalRowCount attribute will still be present in the response.
Whenever I try to query for the length of a film I get lists of null. The query I use is directly from the "Build query" button on their site and looks like this:
[{
"id": null,
"name": null,
"type": "/film/film",
"/film/film/runtime": []
}]
Ufortunately all the responses I get look like this:
{
"name": "4D Man",
"type": "/film/film",
"/film/film/runtime": [
null
],
"id": "/en/4d_man"
}
I can hover over the links you can see on the query page and see the runtime (in this case 85 minutes) but as you can see all I get from the query is null. This may be a Freebase bug, but any help is appreciated. Thank you.
There's not a single runtime of a film, the same film can have different runtimes (original version, director's cut, etc...) Freebase use the film_cut type to contain the different runtimes of a movie
You can use this query to get the runtimes:
[{
"id": null,
"name": null,
"/film/film/runtime": [{
"runtime": null
}]
}]
Tune this query to your needs, you may need type_of_film_cut or film_release_region.
I want to query all recipients of the Nobel Peace Prize and the date (year) from Freebase. I looked at the site, which shows me all winners, but if I do the query here, I do only get "null" results!
What I have so far:
[{
"id": "/m/05f3q",
"/award/award_category/winners": []
}]
If you look at the schema for the information that you're trying to query, you can see that what you are getting back is actually an Award Honor object which has a schema like this. It's got a bunch of different properties, but it doesn't have any meaningful name which is why it's coming back as null.
Try something more along the lines of the below (add additional properties as needed):
[{
"type": "/award/award_honor",
"award": {
"id": "/m/05f3q"
},
"award_winner": [{
"id": null,
"name": null
}],
"year": null
}]
[{
"id": "/en/nobel_prize_in_economics",
"/award/award_category/winners": [{
"/award/award_honor/award_winner": [],
"/award/award_honor/year": null,
"/award/award_honor/award": null,
"/award/award_honor/honored_for": []
}]
}]
I cannot do it in just one call, so I do the same for "/en/nobel_prize_in_physiology_or_medicine", "/en/nobel_prize_in_chemistry", "/en/nobel_peace_prize", "/en/nobel_prize_in_literature".
I'm trying to use Freebase to find out what team a professional athlete belongs to.
So I'm trying to do something like this
[{
"id": null,
"name": "Kobe Bryant",
"type": "/sports/pro_athlete",
"sports_played": []
}]
query editor
and then extract the property "sport_played" to find out what sport the player belongs to. My plan is to then do a more specific query for "basketball_player" or so until I finde the team name. (Is a simpler way to do this?)
However, I already fail at the first step, because in the results, while the properties sport_played and sport_played_professionally contain a single entry, that entry is null:
{
"code": "/api/status/ok",
"result": [{
"id": "/en/kobe_bryant",
"name": "Kobe Bryant",
"sports_played": [
null
],
"type": "/sports/pro_athlete"
}],
"status": "200 OK",
"transaction_id": "cache;cache03.p01.sjc1:8101;2012-06-13T13:30:20Z;0053"
}
I'm confused: I know from browsing the database that there should be a sport value for this player. And the result clearly shows that there is a single value in the "sports_played" list in the result.
But why is it null? Shouldn't is rather be a reference to a Basketball object?
Your query is asking for a list of sports_played but since you only used square braces it will only return a list of the names of all the matching topics.
If you add curly braces to the query you'll see that sports_played actually returns one topic with name = null (which is what your previous query was showing)
[{
"id": null,
"name": "Kobe Bryant",
"type": "/sports/pro_athlete",
"sports_played": [{}]
}]
This is because the expected value of sports_played is a CVT called Sports played which links athletes to sports for specific periods of time. This is so that we can keep track of athletes that have played multiple sports and know which one is the most current.
If you want to see the values inside the CVT object, you'll need to drill down further like this:
[{
"id": null,
"name": "Kobe Bryant",
"type": "/sports/pro_athlete",
"sports_played": [{
"type": "/sports/pro_sports_played",
"sport": {
"id": null,
"name": null
},
"career_start": null,
"career_end": null
}]
}]
Try it in the Query Editor
The sports_played property isn't really what you want here since it's not necessarily correlated with the properties which contain the team information.
Instead you want to use something along the lines of:
{
"id": null,
"name": "Kobe Bryant",
"/basketball/basketball_player/team" : [{"team":null}],
}]
}
if you wanted to get all the teams for all the Kobe Bryants you could use something like:
[{
"id": null,
"name": "Kobe Bryant",
"/soccer/football_player/current_team" : [{"team":null,"optional":true}],
"/basketball/basketball_player/team" : [{"team":null,"optional":true}],
"/american_football/football_player/current_team" :[{"team":null,"optional":true}]
}]
}]
Unfortunately you'll need to go through the schema by hand and pull out the properties of interest by hand since they're not reliably regular enough to query automatically, but there really aren't that many sports to consider, so it shouldn't take very long to assemble your list.