openblocks icon indicating copy to clipboard operation
openblocks copied to clipboard

Accept String for Total Row Count

Open gboxxx opened this issue 2 years ago • 8 comments

I'm trying to supply a total row count from the Woocommerce API. It provides this, along with total pages, in the headers. I'm getting NaN -> 0. I'm guessing because the header is returning a string?

gboxxx avatar Jan 31 '23 03:01 gboxxx

Can you provide a screenshot of the query for us, including which Woocommerce API you are using and what is the return value

lmx1117 avatar Jan 31 '23 08:01 lmx1117

Woocommerce API V3 using {{get_products.extra.headers.X-WP-Total}}.

CleanShot 2023-01-31 at 09 06 32

Here's an example response copied directly from Openblocks Total Row Count section (X-WP-Total removed to produce):

{"Connection":["keep-alive"],"Content-Type":["application/json; charset=UTF-8"],"X-Robots-Tag":["noindex"],"X-Content-Type-Options":["nosniff"],"Access-Control-Expose-Headers":["X-WP-Total, X-WP-TotalPages, Link"],"Access-Control-Allow-Headers":["Authorization, X-WP-Nonce, Content-Disposition, Content-MD5, Content-Type"],"Cache-Control":["no-cache, must-revalidate, max-age=0"],"X-QM-overview-time_taken":["2.6683"],"X-QM-overview-time_usage":["1.5% of 178s limit"],"X-QM-overview-memory":["159,583 kB"],"X-QM-overview-memory_usage":["51.9% of 307,200 kB limit"],"X-WP-Total":["740"],"X-WP-TotalPages":["30"],"Link":["<https://mydomain.com/wp-json/wc/v3/products?search&per_page=25&page=2>; rel=\"next\""],"Allow":["GET, POST"],"X-XSS-Protection":["1"],"Referrer-Policy":["no-referrer-when-downgrade"],"X-FW-Server":["Flywheel/5.1.0"],"X-FW-Dynamic":["TRUE"],"X-FW-Hash":["stg_da4e4ee7nv"],"X-FW-Version":["5.0.0"],"Server":["Flywheel/5.1.0"],"X-Cacheable":["NO:Not Cacheable"],"Fastly-Restarts":["1"],"Accept-Ranges":["bytes"],"Date":["Tue, 31 Jan 2023 15:08:40 GMT"],"X-Served-By":["cache-pdk17842-PDK"],"X-Cache":["MISS"],"X-Cache-Hits":["0"],"X-Timer":["S1675177717.348947,VS0,VE2890"],"Vary":["Accept-Encoding"],"X-FW-Serve":["TRUE"],"X-FW-Static":["YES"],"X-FW-Type":["FLYWHEEL_BOT"],"content-length":["66729"]} → 0

gboxxx avatar Jan 31 '23 15:01 gboxxx

It seems like the type of X-WP-Total is array.So you can try to reference it like this:

{{get_products.extra.headers.X-WP-Total[0]}}

Esieve avatar Feb 01 '23 07:02 Esieve

Tried that too.

image

gboxxx avatar Feb 01 '23 11:02 gboxxx

I'm sorry that was my fault! Please try this:

{{get_products.extra.headers['X-WP-Total'][0]}}

Esieve avatar Feb 02 '23 11:02 Esieve

That did the trick! May be worth noting that Handlebar statement worked in both Appsmith & Retool.

I'm not a developer, but still learning all the various ways to access data via Handlebars and dot notation (learned about currentRow.blahblah [0]?.bleh the other day). Thanks for the help!

gboxxx avatar Feb 02 '23 12:02 gboxxx

Hi @gboxxx, this issue has been fixed in Openblocks v1.1.6. Now you can use dot notations to access properties named with hyphens(-) successfully. Please check it out!

Thanks for your support and patience. For more release notes, see Openblocks releases.

YoJayz avatar Feb 24 '23 11:02 YoJayz

Hi @gboxxx, this issue has been fixed in Openblocks v1.1.6. Now you can use dot notations to access properties named with hyphens(-) successfully. Please check it out!

Awesome, thanks for tagging me!

gboxxx avatar Feb 24 '23 18:02 gboxxx