Previous Topic

Next Topic

Web Service Functions in MaxBasic

Selected functions are available over Web Services, where the Web Service module is installed, as End Points. You can use Web Service Functions to interact with a remote server.

See the End Points for each Module, for a list of functions available.

For information on setting the HTTP request header, see Web Service Header.

Web Service MaxBasic Example

The following MaxBasic code can be used to utilise Web Service functions. Add the required URL in the first line, and add the required function in the Response = line, second from the last.

const URL = "http(s)://{domain}:{port}/{serviceroot}/odata4/v1/company({company})/"

Function MakeCall(EndPoint as String) as Object

Dim Http as Object

Http = CreateObject("Accredo.HttpRequest")'

Dim FinalUrl as String

FinalUrl = URL & Endpoint

FinalURL = URLEncode(FinalURL)

Http.URL = FinalURL

Http.ContentType = "application/json"

Http.SetRequestHeader("format","odata.metadata=full")

Dim Resp as String

Resp = Http.Get

If Http.ResponseCode = 200 or Http.ResponseCode = 201 or Http.ResponseCode = 202 Then

Dim Json as Object

If Resp <> "" Then

Json = ParseJSON(Resp)

Else

Json = JSONCreateObject

End If

Return Json

Else

Error ("Error making request. " & Http.ResponseCode & " - " & Http.ResponseText)

End If

End Function

Dim Response as Object

'Add the required function here. For example:

Response = MakeCall("AddPeriod(PeriodID=306,OffSet=12,Financial=False)")

Print JSONStringify(Response)

See the individual Actions and Functions topics for available end points.

In This Section

Web Service Header

See Also

Web Service

Book Contents

Book Index