Start a new topic

Error 401 Unauthorized using Portal via Api

Hi,

i want to open portal via api using single sign on, but i always get the error "401 Unauthorized" when calling Portal.open() in javascript. The exact request that fails is:

POST https://<sitename>.chargebee.com/api/internal/ssp_users/activate_token

When doing this, the portal opens and a screen "Token has expired." shows up.

What am i doing wrong? Thanks.      

$(document).ready(function () {
    Chargebee.init({
        site: "<sitename>"
    });
});

function openChargebeePortal() { //called on click
    var chargebeeInstance = Chargebee.getInstance();
    chargebeeInstance.setPortalSession(function () {

        return new Promise(function (resolve, reject) {
            
            $.ajax({
                url: 'CreatePortalSession',
                method: 'POST',
                data: '{"customerId":"<costumerid>"}',
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (msg) {
                    resolve(msg);
                }
            });
        });
    });

    var cbPortal = chargebeeInstance.createChargebeePortal();

    cbPortal.open({
    });
}

    

//Server code    
public JsonResult CreatePortalSession(string customerId) {
      ApiConfig.Configure(<sitename>, <api-key>);
      EntityResult result = PortalSession.Create()
            .CustomerId(customerId)
            .Request();
      return Json(result.PortalSession);
}

  

Login or Signup to post a comment