You can read, create and write to memos via the Web Service. The following examples show how to manipulate Memos via the Web Service using MaxBasic code.
Retrieve a Memo
The following MaxBasic Code will print details of a Memo with Memo ID 1 from the Web Service, using a GET request to retrieve information. Enter the required URL for your target company in line 3.
Dim HTTPRequest as Object
HTTPRequest = CreateObject("Accredo.HttpRequest")
URL = "ADD URL STRING HERE"
EndPoint = "/ARMemo('1')?$Select=MemoID,AccountCode,Memo&$Expand=Memo"
Dim MyURL as String
MyURL = URL & Endpoint
HTTPRequest.URL = MyURL
HTTPRequest.ContentType = "application/json"
Dim Resp as string
Resp = HTTPRequest.Get
If HTTPRequest.ResponseCode = 200 or HTTPRequest.ResponseCode = 201 or HTTPRequest.ResponseCode = 202 Then
Dim Json as Object
If Resp <> "" Then
Json = ParseJSON(Resp)
Print JSONStringify(Json)
End If
End If
Create a Memo
The following MaxBasic Code will create a Memo via the Web Service, using a POST request. Enter the required URL for your target company in line 3.
Dim HTTPRequest as Object
HTTPRequest = CreateObject("Accredo.HttpRequest")
URL = "ADD URL STRING HERE"
EndPoint = "/ARMemo"
MemoObject = JSONCreateObject
MemoObject.AccountFile = "ARCUST"
MemoObject.AccountCode = "BOWEN"
MemoObject.Subject = "WS Test Full"
MemoObject.MemoType = "M"
MemoObject.Reference = "Another Test"
MemoTextObject = JSONCreateObject(MemoObject, "Memo")
MemoTextObject.Text = "Hello from Web Service"
Data = JSONStringify(MemoObject)
MyURL = URL & Endpoint
HTTPRequest.URL = MyURL
HTTPRequest.Post(Data)
Update a Memo
To update a Memo (or other entity) you will first need to ascertain the ETag for the memo record. The ETag shows the version of the record, like a record revision number. To retrieve an ETag for the Memo with Memo ID 1, use the following MaxBasic Code. Enter the required URL for your target company in line 4.
Dim HTTPRequest as Object
HTTPRequest = CreateObject("Accredo.HttpRequest")
MemoID = 1
URL = "ADD URL STRING HERE"
EndPoint = "/ARMemo('" & MemoID & "')"
MyURL = URL & EndPoint
HTTPRequest.URL = MyURL
ReturnedBody = HTTPRequest.Get
If HTTPRequest.ResponseCode = 200 or HTTPRequest.ResponseCode = 201 or HTTPRequest.ResponseCode = 202 Then
JsonObject = ParseJSON(ReturnedBody)
etag = JsonObject["@odata.etag"]
End If
Once you have the ETag for a record, you can update the record using a PATCH request. The following MaxBasic Code will update the text in the Memo with Memo ID 1, using the etag variable obtained. Enter the required URL for your target company in line 3.
Dim HTTPRequest as Object
HTTPRequest = CreateObject("Accredo.HttpRequest")
URL = "ADD URL STRING HERE"
EndPoint = "/ARMemo('1')"
obj = JSONCreateObject
obj2 = JSONCreateObject(obj, "Memo")
obj2.Text = "Hello from Web Service again"
Data = JSONStringify(obj)
MyURL = URL & Endpoint
HTTPRequest.URL = MyURL
HTTPRequest.SetRequestHeader("If-Match", etag)
HTTPRequest.PATCH(Data)