Is there a JSON/REST version of the Soap get session token api call? | Community
Skip to main content
Ken_Qrious
Level 4
October 16, 2023
Solved

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

  • October 16, 2023
  • 3 replies
  • 1621 views

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>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by AkshayAnand

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

3 replies

LakshmiPravallika
Community Advisor
Community Advisor
October 17, 2023

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-use-restful-api/m-p/588375

 

Regards,

Pravallika.

AkshayAnand
Community Advisor
AkshayAnandCommunity AdvisorAccepted solution
Community Advisor
October 17, 2023

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

Ken_Qrious
Level 4
October 17, 2023

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

Marcel_Szimonisz
Community Advisor
Community Advisor
October 18, 2023

Hello @ken_qrious,

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

Marcel_Szimonisz
Community Advisor
Community Advisor
October 17, 2023

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/