GET api/entity/{entitytype}/{parentid}/attachments/{attachmentid}
Returns the attachment data for the specified id and type
Request Information
URI Parameters
| Name | Description | Type | Additional information |
|---|---|---|---|
| entitytype | string |
Required |
|
| parentid | integer |
Required |
|
| attachmentid | integer |
Required |
Body Parameters
None.
Response Information
HttpResponseMessage| Name | Description | Type | Additional information |
|---|---|---|---|
| Version | Version |
None. |
|
| Content | HttpContent |
None. |
|
| StatusCode | HttpStatusCode |
None. |
|
| ReasonPhrase | string |
None. |
|
| Headers | Collection of Object |
None. |
|
| RequestMessage | HttpRequestMessage |
None. |
|
| IsSuccessStatusCode | boolean |
None. |
Response Formats
application/json
Sample:
Testing attachments via restapi (This is the content of the file)
Example Code in C#
//REQUEST
try
{
string sessionId = set to the sessionId that was received on login;
string entitytype = type of the entity to get
int id = id of the parent entity
int attachmentid = id of the attachment entity
string uri = string.format("http://localhost/restapi/api/entity/{0}/{1}/attachments/{2}", entitytype, id, attachmentid);
HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
//Assumption: CGRestAPI is configured to use WIA
webRequest.Credentials = CredentialCache.DefaultCredentials;
webRequest.Method = "GET";
webRequest.ContentType = "application/json";
webRequest.Headers.Add("sessionid", sessionId);
HttpWebResponse httpWebResponse = (System.Net.HttpWebResponse)webRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
//process the attachment content received
}
catch (Exception ex)
{
HttpWebResponse resp = ((System.Net.HttpWebResponse)(((System.Net.WebException)(ex)).Response));
using (var streamReader = new StreamReader(resp.GetResponseStream()))
{
string respMesg = streamReader.ReadToEnd();
string status = resp.StatusDescription;
}
}