Beispiel #1
0
        /// <summary>
        /// Add invitation. See https://sign.visma.net/api/docs/v1/#action-document-create-invitations
        /// </summary>
        /// <returns>Object with the following properties: String Body. Dictionary(string,string) Headers. int StatusCode</returns>

        public static async Task <object> DocumentAddInvitations([PropertyTab] DocumentAddInvitationsInput input, [PropertyTab] ConnectionOption options, CancellationToken cancellationToken)
        {
            var request = new HttpRequestMessage(
                HttpMethod.Post,
                options.BaseAddress + "/api/v1/document/" + input.DocumentUriId + "/invitations"
                );

            request.Content = new StringContent(input.Body, System.Text.Encoding.UTF8, "application/json");
            request         = await WithAuthHeaders(request, options);

            using (var client = new HttpClient())
            {
                var response = await client.SendAsync(request, cancellationToken);

                var returnResponse = new HttpResponseWithBody
                {
                    Body       = await response.Content.ReadAsStringAsync(),
                    StatusCode = (int)response.StatusCode,
                    Headers    = GetResponseHeaderDictionary(response.Headers, response.Content.Headers)
                };

                if (!response.IsSuccessStatusCode && options.ThrowExceptionOnErrorResponse)
                {
                    throw new WebException($"Request to '{request.RequestUri}' failed with status code {(int)response.StatusCode}. Response body: {returnResponse.Body}");
                }

                return(returnResponse);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get category list. See https://sign.visma.net/api/docs/v1/#get-categories
        /// </summary>
        /// <returns>Object with the following properties: String Body. Dictionary(string,string) Headers. int StatusCode</returns>
        public static async Task <object> CategoriesGet([PropertyTab] ConnectionOption options, CancellationToken cancellationToken)
        {
            var request = await WithAuthHeaders(new HttpRequestMessage(
                                                    HttpMethod.Get,
                                                    options.BaseAddress + "/api/v1/category/"),
                                                options);

            using (var client = new HttpClient())
            {
                var response = await client.SendAsync(request, cancellationToken);

                var returnResponse = new HttpResponseWithBody
                {
                    Body       = await response.Content.ReadAsStringAsync(),
                    StatusCode = (int)response.StatusCode,
                    Headers    = GetResponseHeaderDictionary(response.Headers, response.Content.Headers)
                };

                if (!response.IsSuccessStatusCode && options.ThrowExceptionOnErrorResponse)
                {
                    throw new WebException($"Request to '{request.RequestUri}' failed with status code {(int)response.StatusCode}. Response body: {returnResponse.Body}");
                }

                return(returnResponse);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Add file. See https://sign.visma.net/api/docs/v1/#action-document-add-file
        /// </summary>
        /// <returns>Object with the following properties: String Body. Dictionary(string,string) Headers. int StatusCode</returns>

        public static async Task <object> DocumentAddFile([PropertyTab] DocumentAddFileInput input, [PropertyTab] ConnectionOption options, CancellationToken cancellationToken)
        {
            var request = new HttpRequestMessage(
                HttpMethod.Post,
                options.BaseAddress + "/api/v1/document/" + input.DocumentUriId + "/files" +
                (
                    input.FileName != null ? "?filename=" + HttpUtility.UrlEncode(input.FileName) : ""
                )
                );

            var requestContent = input.ReadFromFile ? new ByteArrayContent(File.ReadAllBytes(input.FileLocation)) : new ByteArrayContent(input.InputBytes);

            requestContent.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
            request.Content = requestContent;
            request         = await WithAuthHeaders(request, options);

            using (var client = new HttpClient())
            {
                var response = await client.SendAsync(request, cancellationToken);

                var returnResponse = new HttpResponseWithBody
                {
                    Body       = await response.Content.ReadAsStringAsync(),
                    StatusCode = (int)response.StatusCode,
                    Headers    = GetResponseHeaderDictionary(response.Headers, response.Content.Headers)
                };

                if (!response.IsSuccessStatusCode && options.ThrowExceptionOnErrorResponse)
                {
                    throw new WebException($"Request to '{request.RequestUri}' failed with status code {(int)response.StatusCode}. Response body: {returnResponse.Body}");
                }

                return(returnResponse);
            }
        }