Legacy Dev Forum Posts

 View Only

Sign Up

Upload Document API 400 error

  • 1.  Upload Document API 400 error

    Posted 06-05-2025 18:24

    Skyler_Keough | 2022-11-04 20:25:14 UTC | #1

    Hello all,

    I am working on a solution to upload an .csv file to a Genesys Cloud workspace via api.

    I have been using the api endpoint /api/v2/contentmanagement/documents.

    I am able to call the endpoint successfully to get the uploadURI. When I then make a multi-part post request to the uploadURI, I get a 400 bad request with no reason code. I am using implicit grant with myself logging in to test the account. I made sure to have the OAuth client have the correct permissions and made sure that my account had the correct permission to upload documents to the specified workspace.

    Here is my code (I try two different multipart post methods, not sure which one is the approved method):

    ContentManagementApi api = new ContentManagementApi(); DomainEntityRef workspaceRef = new DomainEntityRef('myidhere', "my-usecase-here", null); DocumentUpload body = new DocumentUpload("my-usecase-" + DateTime.Now.ToString(), workspaceRef); Document response = await api.PostContentmanagementDocumentsAsync(body, null, null, true); string uploadUri = response.UploadDestinationUri;

    HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Configuration.Default.AccessToken);

    var requestContent = new MultipartFormDataContent(); var csvContent = new ByteArrayContent(data); csvContent.Headers.ContentType = MediaTypeHeaderValue.Parse("text/csv"); requestContent.Add(csvContent, "exampe", "example.csv");

    var csvResponse = await client.PostAsync(uploadUri, csvContent);

    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uploadUri); request.Content = new ByteArrayContent(data); request.Content.Headers.Add("Content-Type", "multipart/form-data"); List<KeyValuePair<string, string>> formData = new List<KeyValuePair<string, string>>(); formData.Add(new KeyValuePair<string, string>("name", "ExampleUpload")); formData.Add(new KeyValuePair<string, string>("filename", "ExampleUpload.csv")); formData.Add(new KeyValuePair<string, string>("Content-Type", "text/csv")); request.Content = new FormUrlEncodedContent(formData); var uploadResponse = await client.SendAsync(request);

    Any advice would be greatly appreciated!

    Skyler


    Skyler_Keough | 2022-11-09 20:04:02 UTC | #2

    Anyone have any ideas here? Still fighting with the 400 error.


    tim.smith | 2022-11-09 20:14:49 UTC | #3

    The documentation for this upload step can be found here: https://developer.genesys.cloud/analyticsdatamanagement/contentmanagement/uploaddocuments#upload-the-document-file. I've noticed the following:

    • you're not setting the Authorization header on the file upload request
    • the Content-Type header in your code is missing the boundary value (I'm not sure if your HTTP library sets this for you or if it's actually missing)
    • you're assigning a ByteArrayContent to request.Content but then overwriting that a few lines later when you set it again to the FormUrlEncodedContent

    system | 2022-12-10 20:15:08 UTC | #4

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 17081