Sending fax via platform Api

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

Do you get any errors? Can you retrieve the correlation ID from the response?

Hi Tim,

there are no errors. This is the upload response:

{"correlationId":"53fa7efb-cfd3-45e8-ada4-9054b805c8cd"}

Regards,

Sven

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--

Hi Tim,

yes that was the reason.

Thanks.

1 Like