Expand my Community achievements bar.

SOLVED

Is there a JSON/REST version of the Soap get session token api call?

Avatar

Level 4

I would like to create a rest version of the following soap call to retreive a session token, is this possible?

 

Soap Call to

{{AdobeCampagin Server}}/nl/jsp/soaprouter.jsp

 

Body (where strLogin=User Id and strPassword=User Password

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:xtk:session">
<soapenv:Header/>
<soapenv:Body>
<urn:Logon>
<urn:sessiontoken></urn:sessiontoken>
<urn:strLogin></urn:strLogin>
<urn:strPassword></urn:strPassword>
<urn:elemParameters>
</urn:elemParameters>
</urn:Logon>
</soapenv:Body>
</soapenv:Envelope>

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Ken_Qrious 

 

You can use the below JS code to generate the sessionToken.

var cnx = new HttpSoapConnection("https://yourServerURL/nl/jsp/soaprouter.jsp");
var session = new SoapService(cnx, 'urn:xtk:session');
session.addMethod("Logon", "xtk:session#Logon",
                    ["sessiontoken", "string", "Login", "string", "Password", "string" ,"Parameters", "NLElement"],
                    ["sessionToken", "string", "sessionInfo", "NLElement", "securityToken", "string"]);

var res = session.Logon("", "UserName", "password", <param/>);//replace these details with actual userid and pass of mc account
var sessionToken = res[0];
var securityToken = res[2];
logInfo('sessionToken = '+ sessionToken)
logInfo('securityToken = '+ securityToken)

 

Regards

Akshay

View solution in original post

6 Replies

Avatar

Community Advisor

Hi @Ken_Qrious ,

 

Here is a reference of a solved community question for the same query, Could you Please refer it and let me know if it helps.

 

https://experienceleaguecommunities.adobe.com/t5/adobe-campaign-classic-questions/get-session-token-...

 

Regards,

Pravallika.

Avatar

Correct answer by
Community Advisor

Hi @Ken_Qrious 

 

You can use the below JS code to generate the sessionToken.

var cnx = new HttpSoapConnection("https://yourServerURL/nl/jsp/soaprouter.jsp");
var session = new SoapService(cnx, 'urn:xtk:session');
session.addMethod("Logon", "xtk:session#Logon",
                    ["sessiontoken", "string", "Login", "string", "Password", "string" ,"Parameters", "NLElement"],
                    ["sessionToken", "string", "sessionInfo", "NLElement", "securityToken", "string"]);

var res = session.Logon("", "UserName", "password", <param/>);//replace these details with actual userid and pass of mc account
var sessionToken = res[0];
var securityToken = res[2];
logInfo('sessionToken = '+ sessionToken)
logInfo('securityToken = '+ securityToken)

 

Regards

Akshay

Avatar

Level 4

Thanks Akshay, this worked like a charm.  You instructions were clear and easy to follow.

Avatar

Community Advisor

Hello @Ken_Qrious,

Hope you understand this won't work outside adobe campaign environment

Avatar

Community Advisor

Hello @Ken_Qrious ,

there is no REST but you can make REST over SOAP

 

 

 // as we are in JSSP you can also use page directives to import libraries
 // <%@ page import="/nl/core/shared/nl.js"%>
  <%  
    loadLibrary('/nl/core/shared/nl.js')
    //with above we can use NL.reuire() instead loadLibrary()
	NL.require('/nl/core/shared/xtk.js')
	.require("xtk:shared/json2.js")
	.require("xtk:common.js")
    .require("/nl/core/api.js")
    .require('/nl/core/jsspcontext.js')//for authentication

 NL.API.init(request, response, {
    jsonOutput: true
    }, function(jsspContext) {
            response.addHeader("Pragma", "no-cache")
            response.addHeader("Cache-Control", "no-cache");
            response.addHeader("Expires", new Date().toGMTString());
            
            //do something resty
   			//ot call other SOAP libraries as needed
   
            document.write(JSON.Stringify({result:"some result"}));
    });
%>

 

 

 

 

Marcel Szimonisz

MarTech Consultant
for more tips visit my blog
https://www.martechnotes.com/