Advertisement
Namokonov

Untitled

Apr 19th, 2021
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const apiKey = "0e2d8482ae31c8eb1d4a304cf56a8699";
  2. const url = "https://api.novaposhta.ua/v2.0/json/";
  3. const sheetNP = "НП";
  4.  
  5.  
  6. function go() {
  7.   const ss = SpreadsheetApp.getActive();
  8.   const sh = ss.getSheetByName(sheetNP);
  9.   const values = sh.getRange("d2:d" + sh.getLastRow()).getValues().filter(h => h[0]);
  10.  
  11.   values.forEach((h, i) => {
  12.     const result = getEr(h);
  13.     sh.getRange("I" + (2 + i)).setValue(result);
  14.     SpreadsheetApp.flush();
  15.   })
  16. }
  17.  
  18.  
  19. function getEr(ttn) {
  20.   let data = {
  21.     "modelName": "TrackingDocument",
  22.     "calledMethod": "getStatusDocuments",
  23.     "methodProperties": {
  24.       "Documents": [
  25.         {
  26.           "DocumentNumber": ttn.toString(),
  27.           "Phone": ""
  28.         }
  29.       ]
  30.     }
  31.   };
  32.  
  33.   let options = {
  34.     "method": "POST",
  35.     "headers": {
  36.       "content-type": "application/json",
  37.       "apiKey": apiKey
  38.     },
  39.     "async": true,
  40.     "crossDomain": true,
  41.     "processData": false,
  42.     "payload": JSON.stringify(data)
  43.   }
  44.  
  45.   let response = UrlFetchApp.fetch(url, options);
  46.   let dataPars = JSON.parse(response.getContentText());
  47.  
  48.   return dataPars.data[0].Status;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement