Все спасибо, получилось решить проблему
URLDownloadToFile не работает
URLDownloadToFile не работает
16.02.2024 13:46:20
Спасибо, сработало. Но выдает не читаемый текс.
Простите за тупость, первый опыт работы с VBA
Изменено: |
|
|
Работа с ответом после API запроса в VBA
16.02.2024 13:09:06
В ответ на запрос API возвращает JSON в виде
{
"offer_id": "PH8865", "updated": true, "errors": [ ] делаю такого рода запрос: Private Sub CommandButton1_Click() Dim response As VbMsgBoxResult response = MsgBox("Выполнить обновление?", vbQuestion + vbYesNo, "Подтверждение действия") If response = vbYes Then Dim ws As Worksheet Dim rng As Range Dim cell As Range Dim jsonData As String Dim xhr As Object Dim response_1 As String Set ws = ThisWorkbook.Sheets("Нов_цена") Dim lastRow As Long lastRow = ws.Cells(ws.Rows.Count, "M").End(xlUp).Row Set rng = ws.Range("M10:N" & lastRow) jsonData = "{""Prices"" : [" isFirstRow = True ' Iterate through each row in the range For Each cell In rng.Rows ' Check if the row is empty isEmptyRow = True For Each innerCell In cell.Cells If Not IsEmpty(innerCell.Value) And IsNumeric(innerCell.Value) Then isEmptyRow = False Exit For End If Next innerCell ' If the row is not empty and all cells contain numeric values, process it If Not isEmptyRow Then jsonData = jsonData & "{" jsonData = jsonData & """price"":""" & (cell.Cells(1, 2).Value) & """," jsonData = jsonData & """product_id"":" & (cell.Cells(1, 1).Value) & "" jsonData = jsonData & "}," End If Next cell ' Remove the trailing comma If Len(jsonData) > 1 Then jsonData = Left(jsonData, Len(jsonData) - 1) End If jsonData = jsonData & "]}" ' Debug the JSON string MsgBox jsonData ' Create WinHttpRequest object Set xhr = CreateObject("WinHttp.WinHttpRequest.5.1") ' Open connection xhr.Open "POST", " ' Set headers xhr.setRequestHeader "Client-Id", xhr.setRequestHeader "Api-Key", xhr.setRequestHeader "Content-Type", "application/json" ' Send data xhr.send jsonData ' Replace "data" with the parameter name expected by your server ' Get response response_1 = xhr.responseText ' Debug the response MsgBox response_1 & "Данные обновлены" ' Clean up Set xhr = Nothing Else MsgBox "" End If End Sub В response_1 получаю текс ответа содержащий только Result, подскажите как извлечь значение по ключу updated? |
|
|