Skip to content

Create cotizaciones0km #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions cotizaciones0km
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Sub CotizarAutoMercadoLibre()

Dim modelo As String
Dim accessToken As String
Dim url As String
Dim http As Object
Dim json As Object
Dim result As Object
Dim i As Integer

' Modelo de auto en A2
modelo = Trim(Cells(2, 1).Value)

' Token de acceso de tu app
accessToken = "APP_USR-5183773064841897-072412-2e137b60093173bd4810074534d37684-242507349"

If modelo = "" Then
MsgBox "Ingresá un modelo en la celda A2"
Exit Sub
End If

' Crear conexión HTTP
Set http = CreateObject("MSXML2.XMLHTTP")

' Construir URL
url = "https://api.mercadolibre.com/sites/MLA/search?q=" & Replace(modelo, " ", "%20") & "%200km&category=MLA1743&sort=price_asc&limit=3"

' Hacer GET
http.Open "GET", url, False
http.setRequestHeader "Authorization", "Bearer " & accessToken
http.Send

' Validar respuesta
If http.Status <> 200 Then
MsgBox "Error al obtener datos: " & http.Status
Exit Sub
End If

' Parsear JSON
Set json = JsonConverter.ParseJson(http.ResponseText)

' Limpiar celdas anteriores
Range("B2:D4").ClearContents

' Mostrar resultados
i = 2
For Each result In json("results")
Cells(i, 2).Value = result("title")
Cells(i, 3).Value = result("price")
Cells(i, 4).Value = result("permalink")
i = i + 1
If i > 4 Then Exit For
Next

MsgBox "Cotizaciones cargadas correctamente."

End Sub