I want to get attribute sets for an attribute group. So before I used an API call just for the attribute groups. And it worked. For this I make the API GET call and it is successful but I can not parse it. If I just put the response.content in a write function it displays but when I add the ParseJSON function I get the try catch block error. The JSON file is a bit large and for this code I get "invalid length" error.
This is the code.
<script runat="server"> Platform.Load("Core", "1"); try { var authEndpoint = 'https://mcx3g81x4fmdkj05rbw0jg9yb19m.auth.marketingcloudapis.com/'; var payload = { client_id: "xxxxxxxxxxxxxxxxxx", client_secret: "xxxxxxxxxxxxxx", grant_type: "client_credentials" , account_id: "xxxxxxxx"}; var url = authEndpoint + '/v2/token' var contentType = 'application/json' var accessTokenRequest = HTTP.Post(url, contentType, Stringify(payload)); //Write(accessTokenRequest.StatusCode); if (accessTokenRequest.StatusCode == 200) { var tokenResponse = Platform.Function.ParseJSON(accessTokenRequest.Response[0]); var accessToken = tokenResponse.access_token var rest_instance_url = tokenResponse.rest_instance_url}; var auth = 'Bearer ' + accessToken; var output = []; var page = 1; var pageSize = 50; var requestUrl = rest_instance_url + "/contacts/v1/attributeSetDefinitions?$page=" + page + "&$pageSize" + pageSize; var req = new Script.Util.HttpRequest(requestUrl); req.emptyContentHandling = 0; req.retries = 2; req.continueOnError = true; req.contentType = "application/json" req.setHeader("Authorization",auth ); req.method = "GET"; req.encoding= "UTF-8" var resp = req.send(); //Write(String(resp.content)) var result = String(resp.content) var obj = Platform.Function.ParseJSON(result); Write(obj.items) // Check the response code if(resp.statusCode == 200) { //var obj = Platform.Function.ParseJSON(String(resp.content)) } } catch (error) { Write("ERRORBIG"+error); } </script>