Exemple #1
0
        /// <summary>
        /// Gets a list of departments for the selected company
        /// This sample uses a dynamic object rather than a class to get the results
        /// For an example how to access properties via a class rather than dynamically see GetSites()
        /// </summary>
        private Task <string> GetDepartmentsAsync()
        {
            // If the site id has not been set on the APIClientFactory then raise an exception.
            // Site id and company id are required headers on the majority of requests for the
            // Sage 200 API, exceptions would include GetSites().
            // In the sample app, get site reads the companies that this user has
            // access to and selects the last one to use as the default company.
            // While the get sites call is not required, you will need some method
            // to identify the company id and site id to include in the request headers.
            // If you do not specify the Site ID and Company ID, a 401 - Unauthorized exception
            // will be thrown.
            if (string.IsNullOrEmpty(APIClientFactory.SiteID))
            {
                throw new Exception("Get Sites, before you can Get Departments");
            }

            // Create a new instance of the APIClient.
            // This sets up the required properties on the APIClient
            // See the APIClientFactory for details of what is set.
            APIClient apiClient = APIClientFactory.CreateNew();

            // Make the Get call to the APIClient, pass in the url from the version onwards
            // e.g. https://api.columbus.sage.com/uk/sage200/accounts/v1/departments becomes
            // v1/departments because the APIClient knows the base url for the API
            return(apiClient.GetAsync("v1/departments"));
        }
Exemple #2
0
        private Task <string> PostDepartmentAsync(string body)
        {
            // Create a new instance of the APIClient.
            // This sets up the required properties on the APIClient
            // See the APIClientFactory for details of what is set.
            APIClient apiClient = APIClientFactory.CreateNew();

            // Make the Post call to the APIClient, pass in the url from the version onwards
            // e.g. https://api.columbus.sage.com/uk/sage200/accounts/v1/departments becomes
            // v1/departments because the APIClient knows the base url for the API
            return(apiClient.PostAsync("v1/departments", body));
        }
Exemple #3
0
        /// <summary>
        /// Gets the sites available to this API user
        /// This sample uses a class based on the API documentation to get the results
        /// For an example how to dynamically access properties see GetDepartments()
        /// This is a Sage 200 API method and is not exposed on other API's
        /// </summary>
        private string GetSites()
        {
            // Create a new instance of the APIClient.
            // This sets up the required properties on the APIClient.
            // See the APIClientFactory for details of what is set.
            APIClient apiClient = APIClientFactory.CreateNew();

            // Make the Get call to the APIClient, pass in the url from the version onwards
            // e.g. https://api.columbus.sage.com/uk/sage200/accounts/v1/sites becomes
            // v1/sites because the APIClient knows the base url for the API
            return(apiClient.Get("v1/sites"));
        }