script to login with username and Password

Hi,

how can I write a script to login a Customer with username and password and come the Session key back.

I have an external application where I want to log in a customer.

I think a EJSCRIPT is perfect.

Any Idea ?

RE: script to login with username and Password

Hi Fabrice,

Stian wrote an answer here that explains it:

https://community.superoffice.com/en/developer/forum/rooms/topic/superoffice-product-api-group/customer-service/login-on-as-customer/

 

In short, do this:

// custId is the ID of the customer you want to log in, replace this with whatever code you've got
Integer custId = 5;
Customer c;
c.load(custId);

c.login();
String url = getExternalProgramCustomer() + "&custSessionKey=" + custId.toString() + "-" + c.getValue("loginSessionKey");

Hope this helps

Av: Simen Mostuen Iversen 23. okt 2018

RE: script to login with username and Password

Hi Simen,

thanks for your help.

My problem is that I don't have the customerid.

I need to make a Login with username and password not with the customerid.

Can I do this ? 

Customer c;
c.setValue(Username, "username");
c.setValue(password, "password");

c.login();
Av: Fabrice Reithinger 23. okt 2018

RE: script to login with username and Password

Hi, you will have to exist as a person in SuperOffice to be able to use it to log in.

How else would you know which data you should display?

 

If you can backtrack a little, and tell me what your intention with this solution is, maybe I can help you a bit more.

Av: Simen Mostuen Iversen 23. okt 2018

RE: script to login with username and Password

Hi Fabrice, take a look this method in the newly opensourced CRMScript library: https://github.com/SuperOffice/CRMScripts/blob/master/Library/lib-auth.crm

Av: Frode Lillerud 24. okt 2018