Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
primecoder
Contributor
Contributor

Creating a new Rest Connection via SendAsync method in Csharp qlik.net Sdk?

I am trying to create a new REST connection through  the below mentioned line of code in C#:

var task= location.App(newAppIdentifier,noVersionCheck:true).Session.SendAsync(1,"CreateConnection",null, <<HOW TO Pass the required Json Params here>>);

My code example:

var task= location.App(newAppIdentifier,noVersionCheck:true).Session.SendAsync(1,"CreateConnection",null, new Object[]{qname,qConnectionURL,qType});

Kindly suggest me how to parse the required details into the Param Object[] args field of the Send Async Method?

 

Labels (1)
7 Replies
Øystein_Kolsrud
Employee
Employee

You rarely use "SendAsync" directly when you work with the SDK as there are C# methods available for all engine API endpoints. In your case you want to use the "CreateConnection" endpoint in this interface:

https://help.qlik.com/en-US/sense-developer/September2020/Subsystems/NetSDKAPIref/Content/Qlik.Engin...

Something like this:

using (var app = location.App(newAppIdentifier))
{
    var connection = new Connection
        {
            Name = qName,
            ConnectionString = qConnectionUrl,
            Type = qType
        };
    app.CreateConnection(connection);
}
Øystein_Kolsrud
Employee
Employee

If you want to do the operation asynchronously, then you would replace the last line with this:

await app.CreateConnectionAsync(connection);

 

primecoder
Contributor
Contributor
Author

Hi Yko, I tried replicating your suggestion but , I am getting invalid parameter error.

I am trying to connect to qlikSense server via a C# Console application, the values for qName, qType and  qConnectionstring have been tested in the engine-Api-explorer for creating a rest connection

-------->please refer below for the values assigned to the variables:

qname:"rest20";

qConnectionstring="CUSTOM CONNECT TO "+" \\\"provider= QvRestConnector.exe"+";"+"<urldetails>";

qType="QvRestConnector.exe".

 

Kindly help me resolving the above issue thank you.

Øystein_Kolsrud
Employee
Employee

I'm afraid I'm not familiar with how to use that endpoint. But from the SDK side it's simply a wrapper for this engine endpoint:

https://help.qlik.com/en-US/sense-developer/September2020/APIs/EngineAPI/services-Doc-CreateConnecti...

So I guess the problem in this case is to get the settings right for this instance:

https://help.qlik.com/en-US/sense-developer/September2020/APIs/EngineAPI/definitions-Connection.html

I can't really help you there, but what I typically do when I try to figure out what settings to use is to look at the websocket traffic in the browser when I do the operation there. So if you know how to create the connection through Qlik Sense, then open the developer tools in Chrome and check what the message looks like in the websocket traffic when you create it. You should be able to find the call to "CreateConnection" there.

primecoder
Contributor
Contributor
Author

Hi Yko,

I went through the Document link based on which i have rendered the code as mentioned below but on execution iam able to create an app but iam failing to create the rest data source with invalid parameters error

A)CODE FOR CONNECTING TO QLIKSENSE SERVER:

static void Main(string[] args)
{
var uri = new Uri("https://server.domain.com");

ILocation location = SetupConnection(uri);
RestDataSourceCreation(location);
}

private static ILocation SetupConnection(Uri uri)
{
ILocation location = Qlik.Engine.Location.FromUri(uri);

location.AsNtlmUserViaProxy(proxyUsesSsl: true);
return location;
}

---------------------------------------------------------------------------

B)CODE FOR CREATING APP AND CONFIGURING REST DATA SOURCE

private static void RestDataSourceCreation(ILocation location)
{
try
{
using (IHub hub = location.Hub(noVersionCheck: true))
{
string timeStamp = GetTimeStamp(DateTime.Now);
IAppIdentifier newAppIdentifier = location.CreateAppWithName("TestURLDataSourceAPP" + timeStamp);
string qName = "restConnection";
string qType = "QvRestConnector.exe";
string qConnectionString = "CUSTOM CONNECT TO" + " \\\"provider" + "=" + "QvRestConnector.exe" + ";" + "url" + "=" + "http://dummy.restapiexample.com/api/v1/employees;timeout=30;method=GET;httpProtocol=1.1;isKeepAlive=..."";

using (var app = location.App(newAppIdentifier))
{
var connection = new Connection { Name = qName, ConnectionString = qConnectionString.Trim(), Type = qType };
app.CreateConnection(connection);
}

}
}

 

In the above code iam not sure how to specify the connection string accurately:

1)Should we specify CONNECT TO & PROVIDER?

2)can you kindly suggest on how to specify the URL data source with required properties

 

 

Øystein_Kolsrud
Employee
Employee

I'm afraid I can't help you here. I'm not familiar with how to specify those connector settings. You might want to try an post your question on this forum:

https://community.qlik.com/t5/Qlik-Sense-Integration-Extensions-APIs/bd-p/qlik-sense-integration-ext...

I think you are more likely to find someone there who knows this part of the engine API.

vve
Employee
Employee

Hi,

In Sense Windows Client communicates with the custom connector to get hold of the connection string.

With this information it can set proper qConnectionString value.

https://help.qlik.com/en-US/sense-developer/September2020/Subsystems/QVXSDKAPI/Content/Sense_QVXSDKA...