How to access the API using nopCommerce ?

6 anos atrás
How to load products from NOP into WPf List ?
6 anos atrás
khalil_sandilkar wrote:
How to load products from NOP into WPf List ?

There has already been a similar question, you can watch it here
6 anos atrás
i have installed this plugin,but How to use this API plugin in my code ?
6 anos atrás
khalil_sandilkar wrote:
i have installed this plugin,but How to use this API plugin in my code ?


You need to obtain an Access Token and use it to access the API endpoints.
Here is a sample application that demonstrates the authorization process of obtaining an access token.

Please note that the API plugin is still in development and some of the functionality is not complete yet. If you have any problems please let is know.

Thanks
Boyko
6 anos atrás
khalil_sandilkar wrote:
i have installed this plugin,but How to use this API plugin in my code ?


You can access the API plugin documentation by accessing this address in your nopCommerce website.
www.yourstorename.com/swagger/ui/index
5 anos atrás
I am having difficulties assessing the api.. used my email address and password i used for the webportal to login and i was blocked out... how do i go about using this api.
thanks
1 mês atrás
--- Access API methods(Get,Post,Put,Delete)

----
public readonly static string CONTENT_TYPE = "application/json";
---


//Get Method
public string GetAsync(string endpoint)
        {
            try
            {
                var client = _httpClientFactory.CreateClient(NopHttpDefaults.DefaultHttpClient);
                client.DefaultRequestHeaders.Add("api-token", yourkey);
                var response = client.GetAsync(baseUrl + endpoint).Result;
                if (response == null || response.Content == null)
                    return null;
                return response.Content.ReadAsStringAsync().Result;
            }
            catch (Exception ex)
            {
                _logger.Error("message", ex);
            }
            return null;
        }

//Post Method
        public string PostAsync(string endpoint, string content)
        {
            var baseUrl = "base url";
            if (string.IsNullOrEmpty(baseUrl))
                return null;

            var request = new StringContent(content, Encoding.UTF8, PluginDefaults.CONTENT_TYPE);
            request.Headers.Add("api-token", yourkey);
            try
            {
                var client = _httpClientFactory.CreateClient(NopHttpDefaults.DefaultHttpClient);
                var response = client.PostAsync(baseUrl + endpoint, request).Result;
                if (response == null || response.Content == null)
                    return null;

                return response.Content.ReadAsStringAsync().Result;
            }
            catch (Exception ex)
            {
                _logger.Error("message", ex);
            }
            return null;
        }

//Put Method
        public string PutAsync(string endpoint, string content)
        {
            var baseUrl = "base url";
            if (string.IsNullOrEmpty(baseUrl))
                return null;
            try
            {
                var client = _httpClientFactory.CreateClient(NopHttpDefaults.DefaultHttpClient);
                var httpContent = new StringContent(content, Encoding.UTF8, PluginDefaults.CONTENT_TYPE);
                client.DefaultRequestHeaders.Add("api-token", yourkey);
                var response = client.PutAsync(baseUrl + endpoint, httpContent).Result;
                if (response == null || response.Content == null)
                    return null;

                return response.Content.ReadAsStringAsync().Result;
            }
            catch (Exception ex)
            {
                _logger.Error("message", ex);
            }
            return null;
        }

//Delete Method
        public string DeleteAsync(string endpoint)
        {
            var baseUrl = "base url";
            if (string.IsNullOrEmpty(baseUrl))
                return null;
            try
            {
                var client = _httpClientFactory.CreateClient(NopHttpDefaults.DefaultHttpClient);
                client.DefaultRequestHeaders.Add("api-token", yourkey);
                var response = client.DeleteAsync(baseUrl + endpoint).Result;
                if (response == null || response.Content == null)
                    return null;
                return response.Content.ReadAsStringAsync().Result;
            }
            catch (Exception ex)
            {
                _logger.Error("message", ex);
            }
            return null;
        }