1

I am trying to get the list of current Marketing Cloud Users using REST API with GET YOUR_SUBDOMAIN.auth.marketingcloudapis.com/v2/userinfo as shown below.

<script runat="server">
  Platform.Load("Core", "1");
  try {
    /* get OAuth 2.0 access token */
    var payload = '{"grant_type": "client_credentials",';
    payload += '"client_id": "xxxxxxxxxxxxxxxxxxxxxxxx",';
    payload += '"client_secret": "xxxxxxxxxxxxxxxxxxxxxxxx",';
    payload += '"scope": null,';
    payload += '"account_id": "xxxxxxxxx"}';
    var OAuth2URL = "https://SUBDOMAIN.auth.marketingcloudapis.com/v2/token";
    var contentType = 'application/json';
    var accessTokenResult = HTTP.Post(OAuth2URL, contentType, payload);
    var tokenObj = Platform.Function.ParseJSON(accessTokenResult["Response"][0]);
    var accessToken = tokenObj.access_token;
    var headerNames = ["Authorization"];
    var headerValues = ["Bearer " + accessToken];

    /* make the API call and get the response */
    //var content = [0];
    var urlCreate = "https://SUBDOMAIN.auth.marketingcloudapis.com/v2/userinfo";
    var response = HTTP.Get(urlCreate, contentType, headerNames, headerValues);
    Write(Stringify(response));
  }
  catch(e) {
    Write("Error Message: " + Stringify(e));
  }
</script>

However, I am keep getting an error message saying:

{"message":"Unable to retrieve security descriptor for this frame.","description":"System.InvalidOperationException: Unable to retrieve security descriptor for this frame. - from mscorlib\r\n\r\n"}

Has anyone ever encounter the same issue?

Basically, what I want to achieve here is to get the list of current active MC users and display their username & email address in the cloudpage.


Thanks for looking into this @Gortonington

These is the error message that I am currently getting:

{"message":"An error occurred when attempting to evaluate a HTTPGet function call. See inner exception for details.\r\n ClientID: MID12345\r\n JobID: 0\r\n ListID: 0\r\n BatchID: 0\r\n SubscriberID: 0\r\n URL: https://SUBDOMAIN.rest.marketingcloudapis.com/platform/v1/accounts/MID12345/users\r\n","description":"ExactTarget.OMM.FunctionExecutionException: An error occurred when attempting to evaluate a HTTPGet function call. See inner exception for details.\r\n ClientID: MID12345\r\n JobID: 0\r\n ListID: 0\r\n BatchID: 0\r\n SubscriberID: 0\r\n URL: https://SUBDOMAIN.rest.marketingcloudapis.com/platform/v1/accounts/MID12345/users\r\n Error Code: OMM_FUNC_EXEC_ERROR\r\n - from Jint --> \r\n\r\n --- inner exception 1---\r\n\r\nExactTarget.OMM.OMMException: An exception occurred when attempting to retrieve content by a HttpGet call. URL: https://SUBDOMAIN.rest.marketingcloudapis.com/platform/v1/accounts/MID12345/users\r\n Error Code: HTTP_WB_RTV\r\n - from OMMCommon --> \r\n\r\n --- inner exception 2---\r\n\r\nSystem.Net.WebException: The remote server returned an error: (403) Forbidden. - from System\r\n\r\n\r\n\r\n\r\n\r\n"}

4

So first thing of note is that you used the 'auth' endpoint for both (https://SUBDOMAIN.auth.marketingcloudapis.com). When the 'urlCreate' should be using: https://SUBDOMAIN.rest.marketingcloudapis.com.

Second, I noticed you added in a 'contentType' parameter to the HTTP.Get function, which does not exist. This would need to be removed and was a likely culprit for your initial received error. Should be: HTTP.Get(urlCreate, headerNames, headerValues)

Thirdly, I have not heard of v2/userinfo before and it does not even contain the normal structure that the REST endpoints utilize and the only released v2 endpoint for public consumption is around the Authentication process.

I investigated this endpoint and have found no evidence that it is valid. If you have any evidence or documentation on this, I would be happy to ingest it and further explore there.

BUT to get the end result that you want, there is an endpoint in REST that should provide this: /platform/v1/accounts/{{mid}}/users. This is only for that specific MID declared, but it will give all current user info.

So basically you would want to rewrite your script above to:

%%[ SET @mid = [memberid]
]%%

<script runat="server">
  Platform.Load("Core", "1");
  var mid = Variable.GetValue("@mid");

  try {
    /* get OAuth 2.0 access token */
    var payload = '{"grant_type": "client_credentials",';
    payload += '"client_id": "xxxxxxxxxxxxxxxxxxxxxxxxx",';
    payload += '"client_secret": "xxxxxxxxxxxxxxxxxxxxxxxx",';
    payload += '"scope": null,';
    payload += '"account_id": "xxxxxxxxx"}';
    var OAuth2URL = "https://SUBDOMAIN.auth.marketingcloudapis.com/v2/token";
    var contentType = 'application/json';
    var accessTokenResult = HTTP.Post(OAuth2URL, contentType, payload);
    var tokenObj = Platform.Function.ParseJSON(accessTokenResult["Response"][0]);
    var accessToken = tokenObj.access_token;
    var headerNames = ["Authorization"];
    var headerValues = ["Bearer " + accessToken];

    /* make the API call and get the response */
    //var content = [0];
    var urlCreate = "https://SUBDOMAIN.rest.marketingcloudapis.com/platform/v1/accounts/" + mid + "/users";
    var response = HTTP.Get(urlCreate, headerNames, headerValues);
    Write(Stringify(Platform.Function.ParseJSON(response.Content).items));
  }
  catch(e) {
    Write("Error Message: " + Stringify(e));
  }
</script>
8
  • Hi @Gortonington , Thanks for the detailed information. I also wasn't sure if v2/userinfo endpoint would give me what I want or not. Thanks once again!
    – jcloud
    Jan 29 '20 at 22:55
  • Apologies to bother you once again, but would you happen to have a document on the /platform/v1/accounts/mid/users endpoint? It's just that I am now getting an error message saying: An error occurred when attempting to evaluate a HTTPGet function call. See inner exception for details.\r\n ClientID: MID12345\r\n JobID: 0\r\n ListID: 0\r\n BatchID: 0\r\n SubscriberID: 0\r\n URL: SUBDOMAIN.rest.marketingcloudapis.com/platform/v1/accounts/…\r\n","description":"ExactTarget.OMM.FunctionE...
    – jcloud
    Jan 29 '20 at 23:40
  • It is undocumented, so there is no documentation available for it. Can you either update your question with the full error for me to better review or add in your current code to it? Also, can you show me where you got the v2/userinfo endpoint from? I would love to look more into that if possible. Jan 30 '20 at 1:42
  • Thanks for the response once again. :-) I got the idea from on of the posts in the StackExchange: salesforce.stackexchange.com/questions/249109/… and also there is a documentation: developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/…
    – jcloud
    Jan 30 '20 at 4:46
  • I have also updated my question with the full error message. Thanks,
    – jcloud
    Jan 30 '20 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.