====== 4.3 Write Data with VBA ======
Create, update, and delete records.
===== Insert New Record =====
Sub NewCustomer()
Dim http As Object
Dim url As String
Dim body As String
url = "http://localhost:5000/api/v1/dsn/demo/tables/Customers"
body = "{""Name"":""New Company Ltd"",""Country"":""Germany""}"
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "POST", url, False
http.setRequestHeader "Content-Type", "application/json"
http.send body
If http.Status = 200 Then
MsgBox "Successfully created!"
Else
MsgBox "Error: " & http.responseText
End If
End Sub
===== Update Record =====
Sub UpdateCustomer()
Dim body As String
body = "{""primaryKey"":{""Id"":42},""fields"":{""Name"":""Updated""}}"
http.Open "PUT", url, False
http.setRequestHeader "Content-Type", "application/json"
http.send body
End Sub
===== Delete Record =====
Sub DeleteCustomer()
http.Open "DELETE", url & "?Id=42", False
http.send
End Sub