Discussions
API to attachment to invoice?
about 6 years ago by Matt
I’m having trouble attaching a file to an invoice using the API. I have successfully attached using Postman. Here is the C# code I’m attempting and the response.Content back.
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
var client = new RestClient("https://am-api.corrigopro.com/Direct/api/invoice/attachments/");
var request = new RestRequest(Method.POST);
//request.AddHeader("Postman-Token", "3e3fc50c-506e-4ca0-ad78-75ab8d4d651c");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Authorization", string.Format("Bearer {0}", accessToken));
//request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"File\"; filename=\"C:\\Users\\matt\\Desktop\\Safeway_SWY #0932 - San Rafael_2213826_09325746.pdf\"\r\n" +
"Content-Type: application/pdf\r\n\r\n\r\n" +
"------WebKitFormBoundary7MA4YWxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"WorkOrderId\"\r\n\r\n728810\r\n" +
"------WebKitFormBoundary7MA4YWxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"Name\"\r\n\r\ncmon\r\n" +
"------WebKitFormBoundary7MA4YWxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"MimeType\"\r\n\r\napplication/pdf\r\n" +
"------WebKitFormBoundary7MA4YWxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"PerformedBy.Name\"\r\n\r\nDiane Toro\r\n" +
"------WebKitFormBoundary7MA4YWxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"MessageId\"\r\n\r\n1B726535-B114-4F85-966E-167CEAF3F6B8\r\n" +
"------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
response.Content = {"Code":2100,"Message":"Model data validation failed","ValidationErrors":[{"FieldName":"request.File","ErrorType":"Mandatory","Message":"The field File is reqired, but missing or empty."}],"MessageId":"1B726535-B114-4F85-966E-167CEAF3F6B8"}
Please help!