title: Fetching $metadata for a specific collection or entity with Odata web services in Microsoft Dynamics NAV 2016
body: <h1>The environment</h1>
  
  <p>As part of an integration project, I need a PHP website to be able to both read from and write to Microsoft Dynamics NAV 2016's Odata services.</p>
  
  <p>Microsoft Dynamics NAV 2016 uses <a href="http://www.odata.org/documentation/odata-version-3-0/odata-version-3-0-core-protocol/" rel="nofollow">the Odata v3 standard</a>.</p>
  
  <hr>
  
  <h1>The context</h1>
  
  <p>Now, let's take my <code>customer</code> service as an example.</p>
  
  <h3>Fetching a collection of entities</h3>
  
  <p>Fetching an overview of my collection of <code>customer</code> entities works fine, using a link with the following format :</p>
  
  <pre><code>https://&lt;Server&gt;:&lt;WebServicePort&gt;/&lt;ServerInstance&gt;/OData/Company(\'&lt;CompanyName&gt;\')/customer
  </code></pre>
  
  <h3>Fetching a single entity</h3>
  
  <p>Fetching a single <code>customer</code> entity based on <code>id</code> works fine, using a link with the following format :</p>
  
  <pre><code>https://&lt;Server&gt;:&lt;WebServicePort&gt;/&lt;ServerInstance&gt;/OData/Company(\'&lt;CompanyName&gt;\')/customer(\'&lt;Id&gt;\')
  </code></pre>
  
  <h3>Fetching the global metadata</h3>
  
  <p>Getting an overview of the <code>$metadata</code> for all of my services works fine (although it's lacking Json support), using a link with the following format :</p>
  
  <pre><code>https://&lt;Server&gt;:&lt;WebServicePort&gt;/&lt;ServerInstance&gt;/OData/$metadata
  </code></pre>
  
  <h3>Fetching collection-specific metadata</h3>
  
  <p>Now, based on both <a href="http://www.odata.org/documentation/odata-version-3-0/odata-version-3-0-core-protocol/" rel="nofollow">the Odata v3 specs</a> and the value of the <code>odata.metadata</code> property of my customer overview service, I would expect to be able to get an overview of the <code>$metadata</code> of the <code>customer</code> entity, using a link with the following format :</p>
  
  <pre><code>https://&lt;Server&gt;:&lt;WebServicePort&gt;/&lt;ServerInstance&gt;/OData/$metadata#customer
  </code></pre>
  
  <p>This doesn't work as expected. See sub-section <code>The issue</code> below.</p>
  
  <h3>Fetching entity-specific metadata</h3>
  
  <p>Similarly, based on both <a href="http://www.odata.org/documentation/odata-version-3-0/odata-version-3-0-core-protocol/" rel="nofollow">the Odata v3 specs</a> and the value of the <code>odata.metadata</code> property of my dataset when retrieving a single customer, I would expect to be able to get an overview of the <code>$metadata</code> of a single field of the <code>customer</code> entity, using a link with this format :</p>
  
  <pre><code>https://&lt;Server&gt;:&lt;WebServicePort&gt;/&lt;ServerInstance&gt;/OData/$metadata#customer/@&lt;FieldName&gt;
  </code></pre>
  
  <p>This doesn't work as expected. See sub-section <code>The issue</code> below.</p>
  
  <h3>The issue</h3>
  
  <p>For some reason, everything following <code>$metadata</code> appears to be ignored. This means that the last three URLs give me the exact same output, which is not what I expected.</p>
  
  <hr>
  
  <h1>The actual question(s)</h1>
  
  <ul>
  <li>Is it possible to fetch the metadata of just one collection or entity, as I'm trying in sub-sections <code>Fetching collection-specific metadata</code> and <code>Fetching entity-specific metadata</code> of my <code>The context</code> section hereabove?</li>
  <li>If yes, what I doing wrong here? What am I missing?</li>
  </ul>