Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › How to implement “Fetch Movie Data from Web Service” example
Tagged: Script
- This topic has 8 replies, 4 voices, and was last updated 3 years, 9 months ago by Brendan.
-
AuthorPosts
-
March 1, 2021 at 11:57 AM #43646
Ray RobillardParticipantHi !
I’ve created my movie database and now I’m ready to automate data entry with the script example “Fetch Movie Data from Web Service” found here : https://www.tapforms.com/help-mac/5.3/en/topic/scripts (near the bottom of the page)
I’ve created the required fields which my database didn’t have (genre, link, barcode).
I’ve copied the script from the web into a script attached to bar_code field. I’ve adapted the script so it uses my own database field IDs (so far, so good!)
Synced the database with my iPhone. Added a new record, then tap on bar code field, used the scan bar code option and it actually scanned the bar code. However, no field were populated. So I manually checked the web url from where the data is fetched and I got this error :
{“code”:”EXCEED_LIMIT”,”message”:”Rate limit exceeded”}
The full URL is : https://api.upcitemdb.com/prod/trial/lookup?upc=786936203387
Movie really exists and can be found on Amazon.ca website. This is the link I get when I manually enter the UPC : https://www.amazon.ca/s?k=786936203387&ref=nb_sb_noss
So my questions :
1) Did I do everything correctly ? Script attached to a field, and when data is entered in that field, the script is triggered and should search and find the metadata I need ?
2) Is the website used in the sample still working ?
Thanks,
Ray
Attachments:
You must be logged in to view attached files.March 1, 2021 at 12:27 PM #43649
Ray RobillardParticipantOops… made a few mistakes in my explanation :
The script is NOT attached to bar code. It was attached to a different field. When I tried to attached it to bar code, I can’t get bar code to scan (it can’t be tapped).
However, the error remains on the info website.
So my questions :
a) How to implement this
b) does the website still works.March 1, 2021 at 4:02 PM #43651
Daniel LeuParticipantThe error message provides a hint: Rate limit exceeded
Assuming you are using the free tier (https://devs.upcitemdb.com/), the limit is 100 combined requests / day. It looks like you have performed more requests than it is supported for the free tier.
I would wait until tomorrow and try again. Otherwise, check that in your form you perform this lookup only once and not for all records.
Using your link, I get a valid response. So this part of the code is correct:
{"code":"OK","total":1,"offset":0,"items":[{"ean":"0786936203387","title":"Inspector Gadget 2 (DVD)","description":"Inspector Gadget 2 (DVD)","upc":"786936203387","brand":"Disney","model":"08966391","color":"Multi","size":"","dimension":"7.8 X 5.5 X 0.5 inches","weight":"0.3 Pounds","category":"Electronics > Video > Televisions","currency":"","lowest_recorded_price":0.01,"highest_recorded_price":88.88,"images":["https://i5.walmartimages.com/asr/e55d6d37-50d5-4f2e-ab37-e4d83327452c_1.52c7c6439bb862c70630e3116603d231.jpeg?odnHeight=450&odnWidth=450&odnBg=ffffff","http://c.shld.net/rpx/i/s/pi/mp/32762/2379601111?src=http%3A%2F%2Fwww.toysrus.com%2Fgraphics%2Fproduct_images%2FpTRU1-18918266dt.jpg&d=d8d439b1c37fe648b4cb233596449c271086b791","https://pisces.bbystatic.com/image2/BestBuy_US/images/products/4937/4937377_sa.jpg","https://target.scene7.com/is/image/Target/GUEST_2d8658d9-9a48-4370-b0c0-81f82098d03f?wid=1000&hei=1000","http://d3d71ba2asa5oz.cloudfront.net/13000046/images/xp16disd28554d__1.jpg","http://dynamic.indigoimages.ca/dvd/786936203387.jpg?width=200&maxheight=200","https://images10.newegg.com/ProductImageCompressAll200/786936203387-02.jpg","https://tshop.r10s.com/bcc/d8a/48ec/2739/807a/5ecb/e19a/1190e793322c600c7373af.jpg?_ex=512x512","http://www.fye.com/amgcover/dvd/full/t2/45/t24575lhows.jpg","http://www.secondspin.com/amgcover/dvd/large/t2/45/t24575lhows.jpg"],"offers":[{"merchant":"DealYard","domain":"dealyard.com","title":"INSPECTOR GADGET 2 (DVD/1.66)","currency":"","list_price":"","price":12.43,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=v2q253t2v2z284a4u2&tid=1&seq=1614639577&plt=320d6f9194c9f0c32b30ab7b7f6261ea","updated_t":1484913282},{"merchant":"Indigo Books & Music","domain":"chapters.indigo.ca","title":"Inspector Gadget 2","currency":"CAD","list_price":"","price":9.99,"shipping":"Free Shipping","condition":"New","availability":"Out of Stock","link":"https://www.upcitemdb.com/norob/alink/?id=u2w24313y2436484&tid=1&seq=1614639577&plt=27ef67db080fc260bbd78e3fa1877f89","updated_t":1425355506},{"merchant":"Newegg.com","domain":"newegg.com","title":"Inspector Gadget 2 (2003 / DVD)","currency":"","list_price":"","price":10.66,"shipping":"Free Shipping","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=u2v233t20313e4b4v2&tid=1&seq=1614639577&plt=f0a036a392cfa6d3e0678def3d8e14f8","updated_t":1541678901},{"merchant":"Sears","domain":"sears.com","title":"Inspector Gadget 2 DVD","currency":"","list_price":"","price":7.99,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=13s22303y2z2a464&tid=1&seq=1614639577&plt=f49b8656814deabcee725ffe920924ed","updated_t":1425627944},{"merchant":"Rakuten(Buy.com)","domain":"rakuten.com","title":"Inspector Gadget 2","currency":"","list_price":"","price":11.18,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=u2o263t223439494v2&tid=1&seq=1614639577&plt=0d3d67d427c1d7dda095cae2f733528a","updated_t":1590589921},{"merchant":"Best Buy","domain":"bestbuy.com","title":"Inspector Gadget 2 [DVD] [2003]","currency":"","list_price":"","price":7.99,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=w2w233z203z2b464&tid=1&seq=1614639577&plt=8d25e14eae609331acfe38bfd080527f","updated_t":1581124811},{"merchant":"Fye.com","domain":"fye.com","title":"Inspector Gadget 2 (new)","currency":"","list_price":"","price":3.99,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=w2x2x2z2w263d444&tid=1&seq=1614639577&plt=7d22214db23f7e760e61a499a3080cd4","updated_t":1514927053},{"merchant":"SecondSpin.com","domain":"secondspin.com","title":"Inspector Gadget 2 (used)","currency":"","list_price":"","price":4.47,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=x2u253z24303f484&tid=1&seq=1614639577&plt=6f37c48e61dc68d082b815a5cc1c8c8a","updated_t":1438967295},{"merchant":"Wal-Mart.com","domain":"walmart.com","title":"Inspector Gadget 2 (DVD)","currency":"","list_price":"","price":34.85,"shipping":"Free Shipping","condition":"New","availability":"Out of Stock","link":"https://www.upcitemdb.com/norob/alink/?id=y2s203x2v2136484&tid=1&seq=1614639577&plt=08df9e37bdb4924e4cf0fdd361528a52","updated_t":1614631925},{"merchant":"Justice & Brothers","domain":"shopjustice.com","title":"Inspector Gadget 2","currency":"","list_price":"","price":8.16,"shipping":"Free Shipping","condition":"New","availability":"Out of Stock","link":"https://www.upcitemdb.com/norob/alink/?id=y2x223z2036364a4&tid=1&seq=1614639577&plt=4cce5d463adc3ecacdd4f3e55114f155","updated_t":1413349795},{"merchant":"Alibris","domain":"alibris.com","title":"Inspector Gadget 2","currency":"","list_price":"","price":2.69,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=z2q2y203y233a454&tid=1&seq=1614639577&plt=d7ff038f8364eccb45b896fb105e5dce","updated_t":1552399841},{"merchant":"Alibris UK","domain":"alibris.co.uk","title":"inspector gadget 2","currency":"GBP","list_price":"","price":5.69,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=x2q2z2034323b474s2&tid=1&seq=1614639577&plt=7c325406675b24455fb6c8915e58852f","updated_t":1552399372},{"merchant":"DVD Planet","domain":"dvdplanet.com","title":"Inspector Gadget 2 - DVD","currency":"","list_price":"","price":8.61,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=13v203z2z233a4c4&tid=1&seq=1614639577&plt=fef5e0755c97d0fc72bc6537310c2582","updated_t":1459397118},{"merchant":"Toys R Us","domain":"toysrus.com","title":"Inspector Gadget 2 DVD","currency":"","list_price":"","price":7.99,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=13v213z2x26374b4&tid=1&seq=1614639577&plt=bab479317d2b80a85d0cc5500c0711ac","updated_t":1422850223},{"merchant":"Target","domain":"target.com","title":"Inspector Gadget 2 (DVD), movies","currency":"","list_price":"","price":9.99,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=u2q223w2w2z274c4q2&tid=1&seq=1614639577&plt=4d9f2eed14331d22bdd1b31b087e840a","updated_t":1589179984},{"merchant":"11 Main","domain":"11Main.com","title":"INSPECTOR GADGET 2","currency":"","list_price":"","price":10.9,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=u2r2y2v2v223d4a4y2&tid=1&seq=1614639577&plt=3ddf259952383c107395dfde73dd125c","updated_t":1437986473},{"merchant":"Pricefalls.com","domain":"pricefalls.com","title":"Inspector Gadget 2 DVD/1.66","currency":"","list_price":"","price":10.52,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=v2q25313w2239484v2&tid=1&seq=1614639577&plt=d681005c829b35d904ad6aba11c00635","updated_t":1484934730},{"merchant":"Betamonline.com","domain":"betamonline.com","title":"Inspector Gadget 2 (DVD)","currency":"","list_price":"","price":5.85,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=v2r2y2130353b494w2&tid=1&seq=1614639577&plt=649c5f126f4db5bb636387661ce30edf","updated_t":1484940186},{"merchant":"Jet.com","domain":"jet.com","title":"Inspector Gadget 2","currency":"","list_price":"","price":7.99,"shipping":"","condition":"New","availability":"","link":"https://www.upcitemdb.com/norob/alink/?id=w2s213x22303c4d4u2&tid=1&seq=1614639577&plt=b207ff0afe233c527fb7cc00b9d6b11c","updated_t":1536543457}],"asin":"B0000764K0","elid":"133512645732"}]}
March 2, 2021 at 5:43 AM #43657
Ray RobillardParticipantI tried again this morning, but I’m still getting the same error message. I’ll try later this afternoon, after a full 24 hours period. But you were right, the code was set to update records on save. Having 800 titles in my database, that could explain why I received the error message.
That said, I still need help on how to implement this. Do I create a field script and put the code in and another field, bar_code, that I use to input the code (or use the camera on the iPhone)… ? So the script will be triggered when text is input in the bar_code field ?
March 2, 2021 at 11:49 AM #43660
Sam MoffattParticipantThe model I use when interacting with remote services that my script field updates another field and only runs if that other field doesn’t have a value. If something is wrong, I can empty out that field and it’ll repopulate it but it means that once that field is set, the script doesn’t poll the remote service. With 800 records and on save you’ll have blown through that quota the first time you saved and they’ll likely hold you to the 24 hour window. The main place I use this model is with a FOREX field for converting remote currency values to local currency (generally an approximation but usually close enough).
The other pattern I do is to cache the responses locally and copy the response I get back and put it on a local web server (MacOS comes with Apache built in). Then I point my script to it and iterate on it until it behaves the way I want. In this situation that would have meant a request to get the sample response back and then once I’m done with development, I switch back to the real one. I also have some caching proxy for some endpoints to be able to capture API responses and also to quickly return identical requests.
March 2, 2021 at 12:01 PM #43661
Ray RobillardParticipantThe model I use when interacting with remote services that my script field updates another field and only runs if that other field doesn’t have a value.
In my case, I have a bar_code field which is empty at first, but gets populated after I use the camera to scan the UPC on the product. I want the search to run when that field is populated. How do I proceed ?
The other pattern I do is to cache the responses locally and copy the response I get back and put it on a local web server (MacOS comes with Apache built in).
This looks like a mock server and this is way over my league :) (last time I programmed something was probably for with Visual Basic 3 under Windows 3.1.. haha !)
March 2, 2021 at 4:23 PM #43668
Ray RobillardParticipantFound the answer to my question. When the Bar Code field gets a value, the script is executed automaticaly.
And now, it’s working fine.
March 2, 2021 at 11:31 PM #43670
Sam MoffattParticipantYou want a field controlled by the script because if you do a recalculation, it’ll re-run all of the scripts in a record. If you recalc an entire form then it’ll check it for everything. If you’re checking if the bar code field is set to a value then you will hit the API again. That will mean that you’ll likely exceed the limit again and you’ll be waiting a day for things to be available again.
For something like this you don’t need a full mock server, just copy and paste to a text file, point Apache at it (plenty of guides on how to do that out there) and then instead of pointing Tap Forms at the real source, you work against the saved file. More complex APIs a little harder but unless there is something truly dynamic in each request, you can get a sample page and use that to develop against.
In any case glad to hear it’s working for you!
March 3, 2021 at 11:33 PM #43680
BrendanKeymasterI’m glad you were able to figure it out.
The trigger mechanism is that if you have a call to
getFieldValue(some_field_id)
in a Script field, Tap Forms will execute the script whenever the value ofsome_field_id
is changed. -
AuthorPosts
You must be logged in to reply to this topic.