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
%%[ | |
VAR @httppost,@apiid,@apistatusCode,@apiresponse,@apitoken | |
SET @apiid = '{"client_id": "client_id","client_secret": "client_secret", "grant_type": "client_credentials","account_id": "MID"}' /* Forming up the string for getting the access token */ | |
SET @httppost = HTTPPost2("https://xyz.auth.marketingcloudapis.com/v2/token","application/json",@apiid,true,@apiresponse,@responseRows) /* Making a POST call to get access token */ | |
IF(@httppost == "200") Then /* If status is Sucess */ | |
set @rows = BuildRowsetFromString(@apiresponse,'"') /* Split the rows based on '"' string */ | |
set @rowCount = rowCount(@rows) | |
if @rowCount > 0 then | |
for @i = 1 to @rowCount do | |
var @apitoken | |
set @row = row(@rows,4) /* 4th row is where we can get the access token */ | |
set @apitoken = field(@row,1) | |
next @i | |
Else | |
output('Error') /* If response does not have any value then return Error */ | |
ENDIF | |
output(concat('success - ',@apitoken)) | |
Else | |
output('Error') /* If response is not sucess then return Error */ | |
ENDIF | |
]%% | |
<br><br> | |
API Token - %%=v(@apitoken)=%% <br><br><br> | |
API Status Code - %%=v(@httppost)=%%<br><br><br> | |
API Response - %%=v(@apiresponse)=%%<br><br><br> | |
API Response Rows - %%=v(@responseRows)=%%<br><br><br> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment