Thank you Daniel,
I've followed your recommandations and it works. What I needed in my C# .Net application was to get the Labels and Field names for custom objects, but also the content of the Picklists of these custom objects. Please find here after the code that I'm pleased to share, and which could perhaps help other developpers.
Step 1 - Create Description Object
public class picklistValues
{
public bool active { get; set; }
public bool defaultValue { get; set; }
public string label { get; set; }
public string validFor { get; set; }
public string value { get; set; }
}
public class fields
{
public string label { get; set; }
public string name { get; set; }
public IList<picklistValues> pickListValues { get; set; }
}
public class ObjectDescription
{
public IList<fields> fields { get; set; }
}
Step 2 - Get JSON Object Description
The url parameter is like /services/data/[APIVerion]/sobjects/[ObjectName]/describe/
public async Task<string> DescribeObject(string url)
{
string descriptionContent = string.Empty;
HttpClient queryClient = new HttpClient();
string restQuery = serviceUrl + url;
// Create the request
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, restQuery);
// Add Token to the header
request.Headers.Add("Authorization", "Bearer " + oauthToken);
//return JSON to the caller
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// Call the endpoint async
try
{
HttpResponseMessage response = await queryClient.SendAsync(request);
descriptionContent = await response.Content.ReadAsStringAsync();
}
catch (Exception e)
{
descriptionContent = e.Message;
}
queryClient.Dispose();
return descriptionContent;
}
Step 3 - Convert the JSON result
The myDescribeAsync method prepares the connection (with ConsumerKey, ConsumerSecret, etc.), prepares the url (with the right API Version and the Object Name), initializes the connection and call asynchronously the DescribeObject (url) method.
// Get the Json Description
string objdescr = await myDescribeAsync("Account");
// Deserialize the Json result the appropriate structure
ObjectDescription objDescr = JsonConvert.DeserializeObject<ObjectDescription>(objdescr);
Hope this could help.
Olivier Crivelli