Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const apiKey = "ваш apiKey";
- const url = "https://api.novaposhta.ua/v2.0/json/";
- const ss = SpreadsheetApp.getActiveSpreadsheet();
- const sheetNP = ss.getSheetByName("НП");
- const sheetSities = ss.getSheetByName("Города");
- function getSities() {
- let data = {
- "modelName": "Address",
- "calledMethod": "getCities"
- };
- let options = {
- "method": "POST",
- "headers": {
- "content-type": "application/json",
- "apiKey": apiKey
- },
- "async": true,
- "crossDomain": true,
- "processData": false,
- "payload": JSON.stringify(data)
- }
- let response = UrlFetchApp.fetch(url, options);
- let dataPars = JSON.parse(response.getContentText());
- let maxSities = dataPars.data.length
- let sities = [];
- let sitiesRef = [];
- for (let i = 0; i < maxSities; i++) {
- sities.push([dataPars.data[i].DescriptionRu])
- sitiesRef.push([dataPars.data[i].Ref])
- }
- sheetSities.getRange(2, 1, maxSities).setValues(sities)
- sheetSities.getRange(2, 2, maxSities).setValues(sitiesRef)
- // console.log([dataPars.data[50]])
- }
- function getPrice() {
- let CitySender = sheetNP.getRange("B2").getValue();
- let CityRecipient = sheetNP.getRange("D2").getValue();
- let time = sheetNP.getRange("F2").getDisplayValue();
- let data = {
- "modelName": "InternetDocument",
- "calledMethod": "getDocumentPrice",
- "methodProperties": {
- "CitySender": CitySender,
- "CityRecipient": CityRecipient,
- "Weight": "15",
- "ServiceType": "DoorsDoors",
- "Cost": "100",
- "CargoType": "Cargo",
- "SeatsAmount": "10",
- "PackCalculate": {
- "PackCount": "1",
- "PackRef": "1499fa4a-d26e-11e1-95e4-0026b97ed48a"
- },
- "RedeliveryCalculate": {
- "CargoType": "Money",
- "Amount": "100"
- }
- }
- };
- let options = {
- "method": "POST",
- "headers": {
- "content-type": "application/json",
- "apiKey": apiKey
- },
- "async": true,
- "crossDomain": true,
- "processData": false,
- "payload": JSON.stringify(data)
- }
- let response = UrlFetchApp.fetch(url, options);
- let dataPars = JSON.parse(response.getContentText());
- sheetNP.getRange("H2").setValue(dataPars.data[0].Cost)
- // console.log(dataPars.data[0].Cost)
- }
- function getDay() {
- let CitySender = sheetNP.getRange("B2").getValue();
- let CityRecipient = sheetNP.getRange("D2").getValue();
- let time = sheetNP.getRange("F2").getDisplayValue();
- let data = {
- "modelName": "InternetDocument",
- "calledMethod": "getDocumentDeliveryDate",
- "methodProperties": {
- "DateTime": time,
- "ServiceType": "WarehouseDoors",
- "CitySender": CitySender,
- "CityRecipient": CityRecipient
- }
- };
- let options = {
- "method": "POST",
- "headers": {
- "content-type": "application/json",
- "apiKey": apiKey
- },
- "async": true,
- "crossDomain": true,
- "processData": false,
- "payload": JSON.stringify(data)
- }
- let response = UrlFetchApp.fetch(url, options);
- let dataPars = JSON.parse(response.getContentText());
- sheetNP.getRange("G2").setValue(dataPars.data[0].DeliveryDate.date)
- // console.log(dataPars.data[0].DeliveryDate.date)
- }
- function getStatus() {
- let ttn = sheetNP.getRange("E2").getValue();
- let data = {
- "modelName": "TrackingDocument",
- "calledMethod": "getStatusDocuments",
- "methodProperties": {
- "Documents": [
- {
- "DocumentNumber": ttn.toString(),
- "Phone": ""
- }
- ]
- }
- };
- let options = {
- "method": "POST",
- "headers": {
- "content-type": "application/json",
- "apiKey": apiKey
- },
- "async": true,
- "crossDomain": true,
- "processData": false,
- "payload": JSON.stringify(data)
- }
- let response = UrlFetchApp.fetch(url, options);
- let dataPars = JSON.parse(response.getContentText());
- sheetNP.getRange("I2").setValue(dataPars.data[0].Status)
- // console.log(dataPars.data[0].Status)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement