javascript - Zapier.com zipcode autofill city and state -


we using zapier.com connect many programs, 1 function need autofill city , state zip code. available in zapier.com setup code zapier run javascript. can't seem figure out , appreciated.

<script type="text/javascript">//<![cdata[     $(function() {     // important: fill in client key     var clientkey; // deleted stack overflow      var cache = {};     var container = $("#example1");     var errordiv = container.find("div.text-error");      /** handle successful response */     function handleresp(data)     {       // check error       if (data.error_msg)         errordiv.text(data.error_msg);       else if ("city" in data)       {         // set city , state         container.find("input[name='city']").val(data.city);         container.find("input[name='state']").val(data.state);       }     }      // set event handlers     container.find("input[name='zipcode']").on("keyup change", function() {       // zip code       var zipcode = $(this).val().substring(0, 5);       if (zipcode.length == 5 && /^[0-9]+$/.test(zipcode))       {         // clear error         errordiv.empty();          // check cache         if (zipcode in cache)         {           handleresp(cache[zipcode]);         }         else         {           // build url           var url = "https://www.zipcodeapi.com/rest/"+clientkey+"/info.json/" +    zipcode + "/radians";            // make ajax request           $.ajax({             "url": url,             "datatype": "json"           }).done(function(data) {             handleresp(data);              // store in cache             cache[zipcode] = data;           }).fail(function(data) {             if (data.responsetext && (json = $.parsejson(data.responsetext)))             {               // store in cache               cache[zipcode] = json;                // check error               if (json.error_msg)                 errordiv.text(json.error_msg);             }             else               errordiv.text('request failed.');           });         }       }     }).trigger("change");       }); //]]></script> 

it looks you're trying use client-side javascript here. won't work in zapier code step because it's meant used in browser (on webpage). make http request in zapier code step, you'll want use fetch (here's documentation on that).

alternatively, simplest way data need api webhook step:

  1. add step zap
  2. choose webhooks zapier , select action
  3. set step this. step return city/state data can use in subsequent steps

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -