0

VIES API

Hi there, I'm trying to get my text fields automatically updated based on the VAT-nr. which is checked on VIES after clicking a button. When I enter the url directly into the Google Chrome search bar, I get a result but I cannot make it work in Ninox, though. Any suggestions to solve this puzzle? Here is what I'm using so far.

 I hope you could help me out, I think this could save a lot of people a lot of time :-)

2 replies

null
    • Sviluppatore Ninox
    • Fabio
    • 17 hrs ago
    • Reported - view

    Hi 

    In general you need do as server because external HTTP calls are blocked or limited on the client side (e.g. scripts running from buttons/UI).
    Running the request server-side makes the VIES call work correctly.

    let response := do as server http("GET", url) end;
    

    Fabio

      • Jarno_Vande_Walle
      • 7 hrs ago
      • Reported - view

       that does the trick indeed, thx! Here is the full code for those who want it:

      let landCode := substr(text(Land), 0, 2);
      let schoonNummer := 'BTW-nr.';
      schoonNummer := replace(replace(schoonNummer, ".", ""), " ", "");
      let url := "https://ec.europa.eu/taxation_customs/vies/rest-api/ms/" + landCode + "/vat/" +
          schoonNummer;
      let response := do as server
              http("GET", url)
          end;
      if response.error then
          alert("Fout bij ophalen gegevens: " + response.error)
      else
          let data := response.result;
          if data.isValid = true then
              Bedrijfsnaam := data.name;
              let fullAddr := text(data.address);
              let cleanAddr := replacex(fullAddr, "\n", "g", "|");
              let addrParts := split(cleanAddr, "|");
              'Straat + nr.' := item(addrParts, 0);
              let pcStad := trim(item(addrParts, 1));
              if pcStad then
                  let spacePos := index(pcStad, " ");
                  if spacePos > 0 then
                      Postcode := substr(pcStad, 0, spacePos);
                      Gemeente := trim(substr(pcStad, spacePos + 1))
                  else
                      Gemeente := pcStad
                  end
              end
          else
              alert("Dit BTW-nummer is niet bekend in VIES.")
          end
      end
      

Content aside

  • Status Answered
  • 7 hrs agoLast active
  • 2Replies
  • 20Views
  • 2 Following