vrvoice1 | 2016-07-19 13:07:24 UTC | #1
Hi,
I want to send a fax with the platform Api. This is the example code: `ConversationsApi faxApi = new ConversationsApi();
FaxSendRequest bodyFax = new FaxSendRequest(Addresses: new List<string>() { "+49xxxxxxxxxxx" }); bodyFax.ContentType = FaxSendRequest.ContentTypeEnum.Applicationpdf; bodyFax.Name = "test.pdf"; bodyFax.TimeZoneOffsetMinutes = 120; var result = faxApi.PostFaxes(bodyFax); var json = bodyFax.ToJson();
HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Configuration.Default.AccessToken);
MultipartFormDataContent form = new MultipartFormDataContent();
byte[] array = File.ReadAllBytes(@"C:\temp\test.pdf");
form.Add(new StringContent("test.pdf"), "name"); form.Add(new ByteArrayContent(array, 0, array.Count()), "file", "test.pdf");
HttpResponseMessage response = httpClient.PostAsync(result.UploadDestinationUri, form).Result;
response.EnsureSuccessStatusCode(); httpClient.Dispose();
string sd = response.Content.ReadAsStringAsync().Result;`
I don't get any error messages, but the fax wasn't send and I don't get a fax conversation. I think there is a problem with the file upload. If I send a fax from mypurecloud.ie I can see the pdf file in the document section. The ones which I send with my code, I cant see.
Regards,
Sven
tim.smith | 2016-07-19 13:23:19 UTC | #2
Do you get any errors? Can you retrieve the correlation ID from the response?
vrvoice1 | 2016-07-19 13:25:41 UTC | #3
Hi Tim,
there are no errors. This is the upload response:
{"correlationId":"53fa7efb-cfd3-45e8-ada4-9054b805c8cd"}
Regards,
Sven
tim.smith | 2016-07-19 14:03:22 UTC | #4
EDITED
It looks like the failure is caused by you not setting the content type when sending the PDF; the server won't infer the content type. You should set the content type in the request body to application/pdf since you're sending a PDF. Give that a try and see if it changes anything. If it doesn't work, I'll need the new context ID.
The request body should look something like this, for a text file:
Request Headers
Content-Type: multipart/form-data; boundary=A4Q9L5049cRQj9hx8FK8I7bep3YXSsN0hTNa
Request Body
--A4Q9L5049cRQj9hx8FK8I7bep3YXSsN0hTNa Content-Disposition: form-data; name="example.txt"; filename="example.txt" Content-Type: text/plain
This is the example.txt file contents. --A4Q9L5049cRQj9hx8FK8I7bep3YXSsN0hTNa--
vrvoice1 | 2016-07-20 06:55:29 UTC | #5
Hi Tim,
yes that was the reason.
Thanks.
system | 2017-08-28 19:25:20 UTC | #6
This post was migrated from the old Developer Forum.
ref: 143