<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Missing property 'token' on type 'AbstractCredentialsResponseElement' in Developer Q&amp;A Forum</title>
    <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Missing-property-token-on-type/m-p/216919#M379</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/59527"&gt;@StephenLHChan&lt;/a&gt;,&amp;nbsp;&lt;CODE&gt;credentialVaultClient.getCredentialsDetails&lt;/CODE&gt;&amp;nbsp;is an asynchronous function, which means it returns a &lt;CODE&gt;Promise&lt;/CODE&gt;. To properly handle this, you should use &lt;CODE&gt;async/await&lt;/CODE&gt;, something like this should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;import {
  CredentialsDetailsTokenResponseElement,
  credentialVaultClient,
} from "@dynatrace-sdk/client-classic-environment-v2";

//...

private async getToken = () =&amp;gt; {
  const resp = await credentialVaultClient.getCredentialsDetails({
    id: dynatraceConfig['API_TOKEN'][this.environmentId][this.env],
  }) as CredentialsDetailsTokenResponseElement;

  return resp.token;
};&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice the keywords&amp;nbsp;&lt;CODE&gt;async&lt;/CODE&gt; in the function declaration and &lt;CODE&gt;await&lt;/CODE&gt; right before the call to the credentials vault. Besides that, notice that I added a type assertion &lt;CODE&gt;as CredentialsDetailsTokenResponseElement&lt;/CODE&gt;, which allows you to properly access &lt;CODE&gt;resp.token&lt;/CODE&gt;. The reason for this is that depending on the type of the credential, the response will be of a concrete type or another (instead of just&amp;nbsp;&lt;CODE&gt;AbstractCredentialsResponseElement&lt;/CODE&gt;), containing different sets of fields. You can see all the different types&amp;nbsp;&lt;A href="https://developer.dynatrace.com/reference/sdks/client-classic-environment-v2/#abstractcredentialsresponseelementtype" target="_self"&gt;in the SDK reference&lt;/A&gt;&amp;nbsp;in the Dynatrace Developer portal.&lt;/P&gt;
&lt;P&gt;Some additional resources:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Promises:&amp;nbsp;&lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" target="_blank"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;async/await:&amp;nbsp;&lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function" target="_blank"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Type assertions:&amp;nbsp;&lt;A href="https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions" target="_blank"&gt;https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Tue, 04 Jul 2023 16:46:52 GMT</pubDate>
    <dc:creator>educampver</dc:creator>
    <dc:date>2023-07-04T16:46:52Z</dc:date>
    <item>
      <title>Missing property 'token' on type 'AbstractCredentialsResponseElement'</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Missing-property-token-on-type/m-p/216911#M378</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;
&lt;P&gt;I tried to use &lt;CODE&gt;credentialVaultClient&lt;/CODE&gt; to retrieve a token stored in the credentials vault. It seems like the property &lt;CODE&gt;token&lt;/CODE&gt; is missing on the type &lt;CODE&gt;AbstractCredentialsResponseElement&lt;/CODE&gt;. Also, I need to copy the response to get the token.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;	private getToken = () =&amp;gt; {
		const resp = credentialVaultClient.getCredentialsDetails({
			id: dynatraceConfig['API_TOKEN'][this.environmentId][this.env],
		});
		const respCopy: any = { ...resp };
		return respCopy.token;
	};&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is my &lt;CODE&gt;package.json&lt;/CODE&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;"dependencies": {
    "@dynatrace-sdk/app-environment": "^1.0.0",
    "@dynatrace-sdk/app-utils": "^0.2.2",
    "@dynatrace-sdk/client-classic-environment-v2": "^1.1.0",
    "@dynatrace-sdk/client-query": "1.2.0",
    "@dynatrace-sdk/error-handlers": "1.1.0",
    "@dynatrace-sdk/navigation": "1.0.0",
    "@dynatrace-sdk/user-preferences": "1.0.0",
    "@dynatrace/strato-components-preview": "0.97.1",
    "@hookform/resolvers": "^3.1.1",
    "joi": "^17.9.2",
    "react": "^17.0.0",
    "react-dom": "^17.0.0",
    "react-hook-form": "^7.45.1",
    "react-router-dom": "^6.4.1"
  }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please advise. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2023 16:50:54 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Missing-property-token-on-type/m-p/216911#M378</guid>
      <dc:creator>StephenLHChan</dc:creator>
      <dc:date>2023-07-04T16:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Missing property 'token' on type 'AbstractCredentialsResponseElement'</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Missing-property-token-on-type/m-p/216919#M379</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/59527"&gt;@StephenLHChan&lt;/a&gt;,&amp;nbsp;&lt;CODE&gt;credentialVaultClient.getCredentialsDetails&lt;/CODE&gt;&amp;nbsp;is an asynchronous function, which means it returns a &lt;CODE&gt;Promise&lt;/CODE&gt;. To properly handle this, you should use &lt;CODE&gt;async/await&lt;/CODE&gt;, something like this should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;import {
  CredentialsDetailsTokenResponseElement,
  credentialVaultClient,
} from "@dynatrace-sdk/client-classic-environment-v2";

//...

private async getToken = () =&amp;gt; {
  const resp = await credentialVaultClient.getCredentialsDetails({
    id: dynatraceConfig['API_TOKEN'][this.environmentId][this.env],
  }) as CredentialsDetailsTokenResponseElement;

  return resp.token;
};&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice the keywords&amp;nbsp;&lt;CODE&gt;async&lt;/CODE&gt; in the function declaration and &lt;CODE&gt;await&lt;/CODE&gt; right before the call to the credentials vault. Besides that, notice that I added a type assertion &lt;CODE&gt;as CredentialsDetailsTokenResponseElement&lt;/CODE&gt;, which allows you to properly access &lt;CODE&gt;resp.token&lt;/CODE&gt;. The reason for this is that depending on the type of the credential, the response will be of a concrete type or another (instead of just&amp;nbsp;&lt;CODE&gt;AbstractCredentialsResponseElement&lt;/CODE&gt;), containing different sets of fields. You can see all the different types&amp;nbsp;&lt;A href="https://developer.dynatrace.com/reference/sdks/client-classic-environment-v2/#abstractcredentialsresponseelementtype" target="_self"&gt;in the SDK reference&lt;/A&gt;&amp;nbsp;in the Dynatrace Developer portal.&lt;/P&gt;
&lt;P&gt;Some additional resources:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Promises:&amp;nbsp;&lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" target="_blank"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;async/await:&amp;nbsp;&lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function" target="_blank"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Type assertions:&amp;nbsp;&lt;A href="https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions" target="_blank"&gt;https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 04 Jul 2023 16:46:52 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Missing-property-token-on-type/m-p/216919#M379</guid>
      <dc:creator>educampver</dc:creator>
      <dc:date>2023-07-04T16:46:52Z</dc:date>
    </item>
  </channel>
</rss>

