Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4802

VAT Checker Apps Script

$
0
0

I'm trying to make VAT checker in Google Apps script, to use in a Google Sheet. My code looks like this:

function VATChecker(input1, input2) {var country = input1var VATid = input2// Builds the VIES URLconst VATUrl = `https://ec.europa.eu/taxation_customs/vies/rest-api/ms/${country}/vat/${VATid}`;const encodedVATUrl = encodeURI(VATUrl);// Fetches & parses the URLconst fetchRequest = UrlFetchApp.fetch(encodedVATUrl);const results = JSON.parse(fetchRequest.getContentText());// Returns the Datavar data = [];results.data.forEach(function(pieceOfData){  data.push(String(pieceOfData.isValid));});if (data = true)  return "VALID";else   return "NOT VALID";

For now it's giving me the following error in the cell with the function:

TypeError: Cannot read property 'forEach' of undefined (line 20).

When manually creating the URL, this is the data that is returned

{"isValid" : true,"requestDate" : "2022-09-29T08:42:50.353Z","userError" : "VALID","name" : "_________________ (there is info here)","address" : "_________________ (there is info here)","requestIdentifier" : "","vatNumber" : "_________________ (there is info here)","viesApproximate" : {"name" : "---","street" : "---","postalCode" : "---","city" : "---","companyType" : "---","matchName" : 3,"matchStreet" : 3,"matchPostalCode" : 3,"matchCity" : 3,"matchCompanyType" : 3  }}

Any suggestions?


Viewing all articles
Browse latest Browse all 4802

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>