Discussions

Ask a Question
Back to All

Upload Contacts csv via API - Getting Request Failed with status code UnsupportedMediaType

I am aple to upload a CSV file using the API Reference page, but when I use the same code in my c# application I get "Request failed with status code UnsupportedMediaType"

Code below. The file is found and is the same file that works if I use the API reference page interactively. Any suggestions? (I tried a few variations - commented out below)

async Task UploadFileToEverbridge(string contactsFilePath,string contactsFileName, string outputFileFulePath, Logger logger)
{
    try
    {
        contactsFilePath = contactsFilePath +@"\"; //add the slash
        logger.Info(contactsFilePath + contactsFileName);
        var options = new RestClientOptions("https://api.everbridge.net/rest/contacts/(org redacted)?uploadMethod=WITH_RECORD_TYPE");
        var client = new RestClient(options);
        var request = new RestRequest("");
        request.AlwaysMultipartFormData = true;
        request.AddHeader("accept", "application/JSON");
        request.FormBoundary = "---011000010111000001101001";
        request.AddHeader("authorization", "Basic (creds redacted));
        request.AddFile("file",outputFileFullPath);
        //request.Addfile("file", outputFileFullPath,ContentType.Plain) //also tried this
        //request.AddFile("file", "Replace.csv"); //original line from API Reference Page

        var response = await client.PostAsync(request);

        logger.Info("Server Response:", response.Content);
    }
    catch (Exception ex)
    {
        logger.Error(ex.Message);
    }
    
}

}