Last active
December 3, 2020 05:09
-
-
Save MamaiRachid/73c00903d43791a0cf1ed0e385bca843 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%[ | |
SET @MID = '50000XXXX' | |
SET @apiCreds = LOOKUP('REST_Credentials', 'apiCreds', 'MID', @MID) | |
SET @apiCreds = DecryptSymmetric(@apiCreds, 'aes', 'INT_PWD', @null, 'INT_SALT', @null, 'INT_IV', @null) | |
]%% | |
<script runat="server"> | |
Platform.Load("Core","1.1.1"); | |
var apiCreds = Variable.GetValue('@apiCreds'); | |
var credentialObj = Platform.Function.ParseJSON(apiCreds); | |
var clientId = credentialObj.clientId; | |
var clientSecret = credentialObj.clientSecret; | |
var authURL = credentialObj.authURL; | |
var tenantURL = authURL.substring(0,36); | |
/* Authentification */ | |
var payload = { | |
client_id: clientId, | |
client_secret: clientSecret, | |
grant_type: "client_credentials" | |
}; | |
var url = authURL + '/v2/token'; | |
var contentType = 'application/json'; | |
var accessToken; | |
try { | |
var accessTokenRequest = HTTP.Post(url, contentType, Stringify(payload)); | |
if(accessTokenRequest.StatusCode == 200) { | |
var tokenResponse = Platform.Function.ParseJSON(accessTokenRequest.Response[0]); | |
accessToken = tokenResponse.access_token; | |
} | |
} catch (error) { | |
Write(Stringify(error)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment