.NET Core C# / Zoho CRM REST APIs / Send Mail from Inventory Module
Back to Collection Items
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Chilkat.Http http = new Chilkat.Http();
bool success;
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "data": [
// {
// "from": {
// "user_name": "Patricia Boyle",
// "email": "p.boyle@abc.com"
// },
// "to": [
// {
// "user_name": "user1",
// "email": "user1@gmail.com"
// }
// ],
// "inventory_details": {
// "inventory_template": {
// "id": "{{inventory_template_id}}",
// "name": "CT Scan Machines.pdf"
// }
// },
// "paper_type": "A4",
// "view_type": "portrait"
// }
// ]
// }
Chilkat.JsonObject json = new Chilkat.JsonObject();
json.UpdateString("data[0].from.user_name","Patricia Boyle");
json.UpdateString("data[0].from.email","p.boyle@abc.com");
json.UpdateString("data[0].to[0].user_name","user1");
json.UpdateString("data[0].to[0].email","user1@gmail.com");
json.UpdateString("data[0].inventory_details.inventory_template.id","{{inventory_template_id}}");
json.UpdateString("data[0].inventory_details.inventory_template.name","CT Scan Machines.pdf");
json.UpdateString("data[0].paper_type","A4");
json.UpdateString("data[0].view_type","portrait");
// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = "<access_token>";
Chilkat.HttpResponse resp = http.PostJson3("https://domain.com/crm/v2.1/Purchase_Orders/{{record_id}}/actions/send_mail","application/json",json);
if (http.LastMethodSuccess == false) {
Debug.WriteLine(http.LastErrorText);
return;
}
Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
resp.GetBodySb(sbResponseBody);
Chilkat.JsonObject jResp = new Chilkat.JsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;
Debug.WriteLine("Response Body:");
Debug.WriteLine(jResp.Emit());
int respStatusCode = resp.StatusCode;
Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode));
if (respStatusCode >= 400) {
Debug.WriteLine("Response Header:");
Debug.WriteLine(resp.Header);
Debug.WriteLine("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "data": [
// {
// "code": "SUCCESS",
// "details": {
// "message_id": "9943645bd4411e51145e0515bd77e380efceba4d78a87bdb6aeb65e530109d6c"
// },
// "message": "Your mail has been sent successfully.",
// "status": "success"
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
string code;
string Message_id;
string message;
string status;
int i = 0;
int count_i = jResp.SizeOfArray("data");
while (i < count_i) {
jResp.I = i;
code = jResp.StringOf("data[i].code");
Message_id = jResp.StringOf("data[i].details.message_id");
message = jResp.StringOf("data[i].message");
status = jResp.StringOf("data[i].status");
i = i + 1;
}
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"data": [
{
"from": {
"user_name": "Patricia Boyle",
"email": "p.boyle@abc.com"
},
"to": [
{
"user_name": "user1",
"email": "user1@gmail.com"
}
],
"inventory_details": {
"inventory_template": {
"id": "{{inventory_template_id}}",
"name": "CT Scan Machines.pdf"
}
},
"paper_type": "A4",
"view_type": "portrait"
}
]
}'
https://domain.com/crm/v2.1/Purchase_Orders/{{record_id}}/actions/send_mail"
Postman Collection Item JSON
{
"name": "Send Mail from Inventory Module",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{access-token}}",
"type": "string"
}
]
},
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"from\": {\n \"user_name\": \"Patricia Boyle\",\n \"email\": \"p.boyle@abc.com\"\n },\n \"to\": [\n {\n \"user_name\": \"user1\",\n \"email\": \"user1@gmail.com\"\n }\n ],\n \"inventory_details\": {\n \"inventory_template\": {\n \"id\": \"{{inventory_template_id}}\",\n \"name\": \"CT Scan Machines.pdf\"\n }\n },\n \"paper_type\": \"A4\",\n \"view_type\": \"portrait\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Purchase_Orders/{{record_id}}/actions/send_mail\"",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Purchase_Orders",
"{{record_id}}",
"actions",
"send_mail\""
]
},
"description": "To send emails through an API."
},
"response": [
{
"name": "SUCCESS RESPONSE",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"from\": {\n \"user_name\": \"Patricia Boyle\",\n \"email\": \"patricia@gmail.com\"\n },\n \"to\": [\n {\n \"user_name\": \"User 2\",\n \"email\": \"user2@gmail.com\"\n }\n ],\n \"inventory_details\": {\n \"inventory_template\": {\n \"id\": \"4150868000000227001\",\n \"name\": \"CT Scan Machines.pdf\"\n }\n },\n \"paper_type\": \"A4\",\n \"view_type\": \"portrait\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Quotes/4150868000004795007/actions/send_mail",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Quotes",
"4150868000004795007",
"actions",
"send_mail"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 10 May 2021 12:46:59 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "190"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Referrer-Policy",
"value": "strict-origin"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-05-10T19:05:30+05:30"
},
{
"key": "clientVersion",
"value": "4019232"
},
{
"key": "clientsubVersion",
"value": "19804a82a902c9fa618d2b359b97e26a"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=63072000"
}
],
"cookie": [
],
"body": "{\n \"data\": [\n {\n \"code\": \"SUCCESS\",\n \"details\": {\n \"message_id\": \"9943645bd4411e51145e0515bd77e380efceba4d78a87bdb6aeb65e530109d6c\"\n },\n \"message\": \"Your mail has been sent successfully.\",\n \"status\": \"success\"\n }\n ]\n}"
},
{
"name": "MANDATORY_NOT_FOUND",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"from\": {\n \"user_name\": \"Patricia Boyle\",\n \"email\": \"p.boyle@abc.com\"\n },\n \"to\": [\n {\n \"user_name\": \"user1\",\n \"email\": \"user1@gmail.com\"\n }\n ],\n \"inventory_details\": {\n \"inventory_template\": {\n \"name\": \"CT Scan Machines.pdf\"\n }\n },\n \"paper_type\": \"A4\",\n \"view_type\": \"portrait\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Quotes/4150868000004795007/actions/send_mail",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Quotes",
"4150868000004795007",
"actions",
"send_mail"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 10 May 2021 12:48:39 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "187"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Referrer-Policy",
"value": "strict-origin"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-05-10T19:05:30+05:30"
},
{
"key": "clientVersion",
"value": "4019232"
},
{
"key": "clientsubVersion",
"value": "19804a82a902c9fa618d2b359b97e26a"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"data\": [\n {\n \"code\": \"MANDATORY_NOT_FOUND\",\n \"details\": {\n \"api_name\": \"id\",\n \"json_path\": \"$.data[0].inventory_details.inventory_template.id\"\n },\n \"message\": \"required field not found\",\n \"status\": \"error\"\n }\n ]\n}"
},
{
"name": "INVALID_DATA",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"from\": {\n \"user_name\": \"Patricia Boyle\",\n \"email\": \"p.boyle@abc.com\"\n },\n \"to\": [\n {\n \"user_name\": \"user1\",\n \"email\": \"user1@gmail.com\"\n }\n ],\n \"inventory_details\": {\n \"inventory_template\": {\n \"id\": \"415086800000022700\",\n \"name\": \"CT Scan Machines.pdf\"\n }\n },\n \"paper_type\": \"A4\",\n \"view_type\": \"portrait\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Quotes/4150868000004795007/actions/send_mail",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Quotes",
"4150868000004795007",
"actions",
"send_mail"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 10 May 2021 12:49:10 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "216"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Referrer-Policy",
"value": "strict-origin"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-05-10T19:05:30+05:30"
},
{
"key": "clientVersion",
"value": "4019232"
},
{
"key": "clientsubVersion",
"value": "19804a82a902c9fa618d2b359b97e26a"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"data\": [\n {\n \"code\": \"INVALID_DATA\",\n \"details\": {\n \"api_name\": \"email\",\n \"json_path\": \"$.data[0].from.email\"\n },\n \"message\": \"Email can't be sent using this from address.Kindly check the allowed from address list\",\n \"status\": \"error\"\n }\n ]\n}"
},
{
"name": "INVALID_DATA",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"from\": {\n \"user_name\": \"Patricia Boyle\",\n \"email\": \"p.boyle@abc.com\"\n },\n \"to\": [\n {\n \"user_name\": \"user1\",\n \"email\": \"user1@gmail.com\"\n }\n ],\n \"inventory_details\": {\n \"inventory_template\": {\n \"id\": \"4150868000000227001\",\n \"name\": \"CT Scan Machines.pdf\"\n }\n },\n \"paper_type\": \"A4\",\n \"view_type\": \"portrait\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Quotes/4150868000004795007/actions/send_mail",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Quotes",
"4150868000004795007",
"actions",
"send_mail"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 10 May 2021 12:49:36 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "216"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Referrer-Policy",
"value": "strict-origin"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-05-10T19:05:30+05:30"
},
{
"key": "clientVersion",
"value": "4019232"
},
{
"key": "clientsubVersion",
"value": "19804a82a902c9fa618d2b359b97e26a"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"data\": [\n {\n \"code\": \"INVALID_DATA\",\n \"details\": {\n \"api_name\": \"email\",\n \"json_path\": \"$.data[0].from.email\"\n },\n \"message\": \"Email can't be sent using this from address.Kindly check the allowed from address list\",\n \"status\": \"error\"\n }\n ]\n}"
},
{
"name": "INVALID_REQUEST_METHOD",
"originalRequest": {
"method": "COPY",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"from\": {\n \"user_name\": \"Patricia Boyle\",\n \"email\": \"p.boyle@abc.com\"\n },\n \"to\": [\n {\n \"user_name\": \"user1\",\n \"email\": \"user1@gmail.com\"\n }\n ],\n \"inventory_details\": {\n \"inventory_template\": {\n \"id\": \"4150868000000227001\",\n \"name\": \"CT Scan Machines.pdf\"\n }\n },\n \"paper_type\": \"A4\",\n \"view_type\": \"portrait\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Quotes/4150868000004795007/actions/send_mail",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Quotes",
"4150868000004795007",
"actions",
"send_mail"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 10 May 2021 12:49:55 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "124"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "X-Frame-Options",
"value": "deny"
},
{
"key": "X-Download-Options",
"value": "noopen"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
}
],
"cookie": [
],
"body": "{\n \"code\": \"INVALID_REQUEST_METHOD\",\n \"details\": {},\n \"message\": \"The http request method type is not a valid one\",\n \"status\": \"error\"\n}"
},
{
"name": "OAUTH_SCOPE_MISMATCH",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"from\": {\n \"user_name\": \"Patricia Boyle\",\n \"email\": \"p.boyle@abc.com\"\n },\n \"to\": [\n {\n \"user_name\": \"user1\",\n \"email\": \"user1@gmail.com\"\n }\n ],\n \"inventory_details\": {\n \"inventory_template\": {\n \"id\": \"{{inventory_template_id}}\",\n \"name\": \"CT Scan Machines.pdf\"\n }\n },\n \"paper_type\": \"A4\",\n \"view_type\": \"portrait\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Purchase_Orders/{{record_id}}/actions/send_mail\"",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Purchase_Orders",
"{{record_id}}",
"actions",
"send_mail\""
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Thu, 13 May 2021 08:21:30 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "113"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Referrer-Policy",
"value": "strict-origin"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-Download-Options",
"value": "noopen"
}
],
"cookie": [
],
"body": "{\n \"code\": \"OAUTH_SCOPE_MISMATCH\",\n \"details\": {},\n \"message\": \"invalid oauth scope to access this URL\",\n \"status\": \"error\"\n}"
}
]
}