Calling One IAM REST API from VB.NET

Hi All,

I need some help from you.

I have below the PowerShell code and it is working fine.

We have a requirement to call this One IAM rest API from VB.Net  code and don't know how to pass all these parameters. Looked on google and tried but always failed.

Does anyone has called REST API from VB.NET code and if so could you please share sample code. Thank you in advance.

$authdata = @{AuthString="Module=DialogUser;User=***;Password=*****"}

$authJson = ConvertTo-Json $authdata -Depth 2

# Login (important, pass the NAME for your session variable in -SessionVariable)

Invoke-RestMethod -Uri "http://<Server>/AppServer/auth/apphost" -Body $authJson.ToString() -Method Post -UseDefaultCredentials -Headers @{Accept="application/json"} -SessionVariable wsession

# Sample 1: Load collection using Post method

$body = @{parameters = @("","98456798","FirstName","LastName","Middle Name","Department name")} | ConvertTo-Json

Invoke-RestMethod -Uri "http://<Server>//AppServer/api/script/CCC_CreateDepartment_TPA" -WebSession $wsession -Method PUT -Body $body -ContentType application/json

Invoke-RestMethod -Uri "http://<Server>//AppServer/auth/logout" -WebSession $wsession -Method Post
Kind Regards,
  • I do not have the full sample code for your question, but the following sample code I have found should answer most of the questions of how to do this in general.

    It uses the 3rd party components RestSharp and NewtonSoft.Json.

    Dim client As New RestSharp.RestClient("http://myAppServer/AppServer")
    client.CookieContainer = New System.Net.CookieContainer
    ' Authenticate against OneIM AppServer
    Dim request = New RestSharp.RestRequest("auth/apphost", RestSharp.Method.POST)
    Dim Body As String = "{""authString"":""Module=DialogUser;User=viadmin;Password=myPassword""}"
    request.RequestFormat = RestSharp.DataFormat.Json
    request.AddHeader("Content-Type", "application/json")
    request.UseDefaultCredentials = True
    request.AddParameter("application/json", Body, RestSharp.ParameterType.RequestBody)
    Dim response As RestSharp.IRestResponse = client.Execute(request)
    If response.StatusCode = Net.HttpStatusCode.OK Then
    	' Fetch password
    	request.Resource = "api/entities/DialogConfigParm"
    	request.Method = RestSharp.Method.GET
    	request.AddQueryParameter("Fullpath", "Custom\DynamicSyncPW")
    	request.AddQueryParameter("displayColumns", "Value")
    	response = client.Execute(request)
    	Dim responseObj As Newtonsoft.Json.Linq.JArray = Newtonsoft.Json.Linq.JArray.Parse(response.Content)
    	Dim pw As String = responseObj.SelectToken("[0].values.Value").ToStringNullSafe
    	If Not String.IsNullOrEmpty(pw) Then
    		log.Debug("Dynamic Sync Password:{0}",pw)
    		Return pw
    		Throw New Exception("Password could not be determined.")
    	End If
    End If
    Throw New Exception("Password could not be determined.")


Reply Children
No Data