Skip to main content
Participant
April 5, 2023
Question

Getting error 403 Forbidden when trying to post to /transientDocuments REST API

  • April 5, 2023
  • 0 replies
  • 654 views

I have successfully managed to implement the Oauth flow which returns me a valid bearer token which according to my understanding, I can use to query the transientDocuments endpoint. So, I have built a method that takes in a pdf file as input to achieve this, but I am getting a 403 forbidden error when trying to complete the request. But when I debug the method and use the bearer token I have there in the Adobe swagger documentation here: https://secure.na4.adobesign.com/public/docs/restapi/v6#!/transientDocuments/createTransientDocument , the request works successfully. So, I am not sure if it is perhaps an issue with how I am adding the file in as form data or if there might be a complication on the configuration side in my Adobe application settings, I have allowed all scopes there so not sure what else the issue could be.

This is the C# code I am using to perform the POST method to the Upload Transient Documents REST API:

public static string uploadTransientDocument(FileData data, string code)
        {
            string token = adobeOuath(code);

            string base64;
            string fileName = ContentDispositionHeaderValue.Parse(data.file.ContentDisposition).FileName.Trim('"');

            var client = new HttpClient();
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            using (var ms = new MemoryStream())
            {
                data.file.CopyTo(ms);
                var fileBytes = ms.ToArray();
                base64 = Convert.ToBase64String(fileBytes);
            }

            var bytes = Convert.FromBase64String(base64);
            var contents = new StreamContent(new MemoryStream(bytes));

            var formContent = new MultipartFormDataContent();
            formContent.Add(contents, "File", fileName);

            var response = client.PostAsync(https://api.echosign.com/api/rest/v6/transientDocuments, formContent);
            var responseBody = response.Result.ToString();

            return responseBody;
        }
This topic has been closed for replies.