Passer au contenu principal
Adaptive Planning
Dernière mise à jour : 2023-06-23
getIntacctSessionID

getIntacctSessionID

Ce script de démarrage d'une SDCP doit être modifié par un développeur JavaScript pour votre cas d'utilisation. Il ne fonctionnera pas sans modification.
Enregistrez le bloc de code ci-dessous sous forme de script dans votre SDCP Sage Intacct et nommez-le getIntacctSessionID.
function getIntacctSessionID(intacctURL,intacctRequestParms) { //get a session id to use for subsequent api calls var xmlSessionIDRequest = '<?xml version="1.0" encoding="iso-8859-1"?><request><control><senderid>' + intacctRequestParms.senderId +'</senderid>' + '<password>' + intacctRequestParms.senderPassword + '</password><controlid>' + intacctRequestParms.control_controlid +'</controlid><uniqueid>' + intacctRequestParms.control_uniqueid + '</uniqueid>' + '<dtdversion>' + intacctRequestParms.control_dtdversion + '</dtdversion></control>' + '<operation> <authentication>' + '<login><userid>' + intacctRequestParms.userID + '</userid><companyid>' + intacctRequestParms.companyId + '</companyid><password>' + intacctRequestParms.userPassword + '</password>'; //clientId and locationId are optional if (intacctRequestParms.clientId !== null && intacctRequestParms.clientId.trim() !== '' ) xmlSessionIDRequest += '<clientid>' + intacctRequestParms.clientId + '</clientid>'; if (intacctRequestParms.locationId !== null && intacctRequestParms.locationId.trim() !== '' ) xmlSessionIDRequest += '<locationid>' + intacctRequestParms.locationId + '</locationid>'; xmlSessionIDRequest += '</login></authentication>' + '<content><function controlid="' + intacctRequestParms.control_controlid + 'XXX"><getAPISession/></function></content></operation></request>'; //send XML request and get response var xmlSessionIDResponse = sendAndGetXML_Intacct(intacctURL,xmlSessionIDRequest); if (xmlSessionIDResponse ) { //we've already checked for success so now need to extract the session id //note, this uses the older xml parser. This parser works fine with smaller payloads but is not recommended for larger ones var parser = ai.xml.createParser(); var xmlDoc = parser.parse(xmlSessionIDResponse.toString()); var apiEl = xmlDoc.getRootElement().getChildElement('operation').getChildElement('result').getChildElement('data').getChildElement('api'); var sessionid = apiEl.getChildElement('sessionid').getText(); var endpoint = apiEl.getChildElement('endpoint').getText(); //var location = apiEl.getChildElement('locationid').getText(); return {'sessionId': sessionid, 'endpoint': endpoint}; } else { //session id not found return false; } }