Attachment
How to POST an Attachment via Visma Net API in C#?
Please read more about the attachment-specific endpoints at Documentation/Swagger
WebClient Class
public void postAttachment(string[] files, string <objectID>, string token, string companyId)
{
using (WebClient client = new WebClient())
{
client.Headers.Add("ipp-company-id", "<companyId>");
client.Headers.Add("ipp-application-type", "Visma.net Financials");
client.Headers.Add("Authorization", "bearer<token>");
for (int i = 0; i < files.Length; i++) // Multiple
{
byte[] responseArray = client.UploadFile(
@"https://api.finance.visma.net/v1/<Endpoint>/<objectID>/Attachment",
"POST",
files[i]
);
}
}
}HttpClient Class
public void postAttachmentHttpClient()
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("ipp-application-type", "Visma.net Financials");
client.DefaultRequestHeaders.Add("ipp-company-id", "<companyID>");
client.DefaultRequestHeaders.Add("Authorization", "Bearer <token>");
HttpResponseMessage response;
var content = new MultipartFormDataContent();
var path = Path.Combine(@"<path>");
string fileName = Path.GetFileName(path);
FileStream fs = File.OpenRead(path);
var sc = new StreamContent(fs);
sc.Headers.Add("Content-Type", "application/octet-stream");
sc.Headers.Add("Content-Disposition","form-data; name=\"file\"; filename=\"" + Path.GetFileName(path) + "\"");
content.Add(sc, "file", fileName);
response = client.PostAsync(@"https://api.finance.visma.net/v1/<endpoint>/<objectID>/Attachment", content).Result;
}
}The sample code is provided “AS IS” and any express or implied warranties, including the implied warranties of merchantability and fitness for a particular purpose, are disclaimed. In no event shall Visma or contributors be liable for any direct, indirect, incidental, special, exemplary or consequential damages.
How to fetch attachment
Step 1. Fetch the attachmentid from the document, for example
GET https://api.finance.visma.net/v1/supplierInvoice/900002

Step 2. Fetch the Base64 using the attachmentid from step one in the attachment endpoint. For example: GET https://api.finance.visma.net/v1/attachment/7319362a-126f-47ca-8bce-669c814b0576

Step 3. Once you have fetched the Base64, you should be able to decode it to a file