Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

infockbox

Newbie
  
  • Posts

    1
  • Joined

  • Last visited

infockbox's Achievements

Newbie

Newbie (1/14)

  • One Month Later
  • Week One Done
  • Conversation Starter

Recent Badges

0

Reputation

  1. Нужна помощь в доработки функционала передача заказа из Opencart в гугл таблицы через api сделал такой скрипт function authorizeAndFetchOrders() { const username = 'api'; // Имя пользователя const apiKey = 'w6IpMcLOQydrbsiL4T6l0CZvvPQr2LNcrDY1QiQQmMqrOfNLG4PCYd0IR5dQmslETfdElIl6K3LSIUMQ18YOowshz7izHrUz06KqJnHBYDatfyN3vvsKHvGcKXoljqvshldn0wKDSVP5rOzbnnfzCCscsmWdgdaSEFkAZ0hDPzZJo3Lc45MWSGzw8Wd4Njll0V3O3xcWUDymjYKSmOMiWoEVDUvhkaVxfkGUzLy54PLlTl58vMSFWrOvmqeqJlo4'; // Ваш API ключ const apiUrl = 'https://shopmag.pp.ua/' + 'index.php?route=api/'; const loginUrl = apiUrl + 'account/login&language=en-gb&store_id=0'; const requestData = { 'username': username, 'key': apiKey }; const options = {'method': 'post', 'contentType': 'application/x-www-form-urlencoded', 'payload': requestData, 'muteHttpExceptions': true}; const loginResponse = UrlFetchApp.fetch(loginUrl, options); const loginStatus = loginResponse.getResponseCode(); if (loginStatus === 200) { const loginData = JSON.parse(loginResponse.getContentText()); Logger.log(JSON.stringify(loginData, null, 2)); // полный ответ в логи, для просмотра раскоментить if (loginData.api_token) { const sessionId = loginData.api_token; // Токен для сессии // URL для получения заказов const ordersUrl = apiUrl + 'sale/order.load&language=en-gb&store_id=0&order_id=1'; // Настройки для запроса получения заказов const ordersOptions = { method: 'post', contentType: 'application/json', headers: { 'Cookie': 'OCSESSID=' + sessionId }, muteHttpExceptions: true }; // Выполнение запроса получения заказов const ordersResponse = UrlFetchApp.fetch(ordersUrl, ordersOptions); const ordersStatus = ordersResponse.getResponseCode(); if (ordersStatus === 200) { const ordersData = JSON.parse(ordersResponse.getContentText()); Logger.log(JSON.stringify(ordersData, null, 2)); // полный ответ в логи, для просмотра раскоментить Logger.log('Заказы:', ordersData); // Выводим заказы в лог } else { Logger.log('Ошибка при получении заказов:', ordersResponse.getContentText()); } } else { Logger.log('Не удалось получить API токен:', loginData); } } else { Logger.log('Ошибка авторизации:', loginResponse.getContentText()); } } получаю такие ответы 14:15:27Информация{ "success": "Сеанс API успешно запущен!", "api_token": "727d4ef9a7ab1877725f3b57ed"} 14:15:28Информация{ "success": "Заказ успешно изменен!"} 14:15:28ИнформацияЗаказы: пробовал менять все вариации ссылки sale/order.info, sale/orders и тд, но выдает ошибку Информация Ошибка при получении заказов: и пустой ответ. авторизацию по айпи убрал, сесия создаеться и коректно добавляеться с куками в запросе. Для теста сделал 2 заказа если запрос const ordersUrl = apiUrl + 'sale/order.load&language=en-gb&store_id=0&order_id=1'; const ordersUrl = apiUrl + 'sale/order.load&language=en-gb&store_id=0&order_id=2'; то ответ Информация{ "success": "Заказ успешно изменен!"} если запрос с номером заказа которого нет const ordersUrl = apiUrl + 'sale/order.load&language=en-gb&store_id=0&order_id=3'; то ответ Информация { "error": "Внимание: Заказ не найден!"} значит с авторизацией и сесией все норм.
×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.