Giter Site home page Giter Site logo

api-for-nopcommerce's Introduction

API plugin for nopCommerce 4.80

This plugin provides a RESTful API for managing resources in nopCommerce 4.8. For the other versions of nopCommerce, please refer to the the other releases and branches.

Installation

  1. clone the NopCommerce repository (develop branch) into folder called nopCommerce
  2. clone this repository into the same folder where the nopCommerce folder is located
  3. build the nopCommerce solution
  4. build the api-for-nopcommerce solution (the output will be placed inside the nopCommerce directory)
  5. run the Nop.Web project in the nopCommerce solution
  6. install the nopCommerce database, create the admin user (skip this step if already done)
  7. go to the administration page, Api plugin should be listed in local plugins configuration section.
  8. in the customers section assign the role Api Users to the user that will be used to access the api.
  9. set fake appId and app secret in facebook authentication plugin as a workaround for issue #17.
  10. go to /api/swagger page and experiment with the api (use the Authorize button to authenticate requests) or run .NET 5 client application (ClientApp project) that contains auto-generated Api client class generated from the swagger json file using C# 9 source generator.

api-for-nopcommerce's People

Contributors

bnoffer avatar d3bo avatar dinukasal avatar freakbyte avatar itanev avatar ivanst-stoyanov avatar jackfagner avatar madewithfire avatar maximg1234 avatar mkabab avatar olek-hzq avatar poyker avatar sdobrev avatar stepanbenes avatar toddca avatar zandiarash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

api-for-nopcommerce's Issues

401 Error

hello
I am getting an error like
How can I fix
content-security-policy: default-src 'self'; connect-src *; font-src * data:; frame-src *; img-src * data:; media-src *; object-src ; script-src * 'unsafe-inline' 'unsafe-eval'; style-src * 'unsafe-inline';
date: Sun,06 Feb 2022 04:33:46 GMT
permissions-policy: accelerometer=(),camera=(),geolocation=(),gyroscope=(),magnetometer=(),microphone=(),payment=
,usb=()
referrer-policy: same-origin
server: Microsoft-IIS/10.0
strict-transport-security: max-age=31536000; includeSubDomains
www-authenticate: Bearer
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-sourcefiles: =?UTF-8?B?QzpcVXNlcnNcVHVhbm5hXFNvdXJjZVxSZXBvc1xucGNcUHJlc2VudGF0aW9uXE5vcC5XZWJcYXBpXGxhbmd1YWdlcw==?=
x-xss-protection: 1; mode=block

api products error: Value cannot be null. (Parameter 'value')

Hello everyone. I can get categories without problem via api. But when i try to get products i get an error.(First i called with default swagger parameters and then i set it null like i used in to get categories)

{
"error": "Value cannot be null. (Parameter 'value')"
}
nopcc

Product Put Problem

Iam trying to put test of product in swagger page, but iam getting error;

  _"Unable to cast object of type 'System.Collections.Generic.List`1[System.Object]' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]'."_

. Iam used nopcommerce sample datas product id = 1 . Body link : https://pastebin.pl/view/03dc6cd3
and ive also attached swagger pages picture with error showing
noppproductput
.

ApiStartup Error

Hi
I Hav Error In ApiStartup Class And ConfigureServices Method

var apiConfig = services.AddConfig<ApiConfiguration>(apiConfigSection);

Error CS1061: 'IServiceCollection' does not contain a definition for 'AddConfig' and no accessible extension method 'AddConfig' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Nop.Plugin.Api)

Please Help me

API and Swagger

I just testing this plugin with swagger, but seem something wrong...
my steps :

  1. press authorize button, and set "Bearer JWT" password

  2. test Token with "https://localhost:44369/token", and api return correctly
    {
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOiIxNjIyMTE0NzY5IiwiZXhwIjoiMTYyMjM3Mzk2OSIsIkN1c3RvbWVySWQiOiI0IiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvbmFtZWlkZW50aWZpZXIiOiJiNjVkZjNiOC01YjU2LTQ1OWYtOWZmYy1kZDhlZDQwNTQ5MzUiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9lbWFpbGFkZHJlc3MiOiJ1bmtub3dAbWFpbC5jb20iLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoidW5rbm93QG1haWwuY29tIn0.xjwE74luvb5cdryTGqq_ExqbeINpCuGEG81TbY7tkPo",
    "token_type": "Bearer",
    "created_at_utc": "2021-05-27T11:26:09.9818257Z",
    "expires_at_utc": "2021-05-30T11:26:09.9818257Z",
    "username": "[email protected]",
    "customer_id": 4,
    "customer_guid": "b65df3b8-5b56-459f-9ffc-dd8ed4054935"
    }

  3. try another api function like "https://localhost:44369/api/products/count", but return a Bearer error

content-security-policy: default-src 'self'; connect-src *; font-src * data:; frame-src *; img-src * data:; media-src *; object-src ; script-src * 'unsafe-inline' 'unsafe-eval'; style-src * 'unsafe-inline'; date: Thu,27 May 2021 11:30:14 GMT permissions-policy: accelerometer=(),camera=(),geolocation=(),gyroscope=(),magnetometer=(),microphone=(),payment=,usb=() referrer-policy: same-origin server: Microsoft-IIS/10.0 strict-transport-security: max-age=31536000; includeSubDomains www-authenticate: Bearer error="invalid_token" x-content-type-options: nosniff x-firefox-spdy: h2 x-frame-options: SAMEORIGIN x-sourcefiles: =?UTF-8?B?RDpcU09VUkNFU1xXb3Jrc1xOb3BGcmFtZXdvcmsuZUxlYXJuaW5nIDQuNFxQcmVzZW50YXRpb25cTm9wLldlYlxhcGlccHJvZHVjdHNcY291bnQ=?= x-xss-protection: 1; mode=block

Getting 403 Forbidden error with the generated token

I have generated the token from the /token endpoint using the following request:

http://localhost:5000/[email protected]&password=yyy

The decoded token includes the following data:

{
  "nbf": "1617831552",
  "exp": "1933191549",
  "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress": "[email protected]",
  "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "20361ca2-605b-4f2b-8c5f-911c9db114c1",
  "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name": "[email protected]"
}

when I use the generated token in the /api/swagger or using postman to make requests I get 403 error.

Sample request

http://localhost:5000/api/categories

Headers

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6I......

Am I missing any configurations in the admin area to make calls enable for my user?

API for mobile app

Hi,
I would like develope a my custom app (Xamarin Forms)
I it possible using this api to login from a android/iphone app ?

How can I get token?

I have installed api-nopcommerce-plugin following your description and I found the swagger api.
But to authorize button, it need to get token.
How can I take?
Please hope for your help.

UpdateProduct problem

Hi,
When I tried to use UpdateProduct method response is "Internel Server Error"
I checked also to update to the product with I took by GetProduct method.
What is the mistake can be ?

Rebuild error

Good day,

I tried to rebuild api-for-nopcommerce following your documentation, but I'm getting 3 errors .

  1. DataSettingsManager' does not contain a definition for 'IsDatabaseInstalledAsync'
  2. ILocalizationService' does not contain a definition for 'AddLocaleResourceAsync
  3. IServiceCollection' does not contain a definition for 'AddConfig' and no accessible extension method 'AddConfig' accepting a first argument of type 'IServiceCollection'.

I did look at the interface ILocalizationService there is no method called AddLocaleResourceAsync

Not build solutions

Hello,
nop api cannot find client interface and class in cs file of ClientApp
It cannot be included in the project because there is an error on the 27th line, how should I proceed?

Bad request error when running ClientApp

Hi,

When running the client app, there's a bad request error when creating a shopping cart item.

I'm also having a similar issue with swagger by getting forbidden errors when requesting the shopping cart, even with the bearer token and correct customer id for the logged in user, although admin access is fine.

Cheers

installation problem on 4.40.4

Hello.

I tried to install this plugin as you documented.

It seems like installable on admin panel. I activated it.

But then application started to crash on startup, by saying someting like "System.IO.FİleNotFoundException" for Microsoft.IdentityModel.Tokens Version 5.5.0.0, and also for Microsoft.IdentityModel.Logging dlls.

I've investigated the problem a little bit and I saw that, in build time, some of the dll's in your plugin was not installed to Nop.Web/Plugins/bin folder. Then when NopEngine.cs tries inject plugin's interfaces to application via reflection, it failes to resolve dependencies.

On top of that my current nopcommerce version has Microsoft.IdentityModels.Tokens version as 5.2.4.0 but this plugin has 5.5.0.0

Do you have any suggestion for my problem?

Swagger api always send 403 error

Swagger api always send 403 error
below the step i did
1- installed the plugin using the way described in github repo readme file
2- solved the facebook plugin issue using the mentioned-in-readme workaround
3- assigned api user permission to admin user
4- login and got a token
5- authenticate using "Authorize" button in swagger ui
6- tried to get Categories using /api/categories api

then i got 403 error at all parameter combinations i did..
also tried some other apis like categories count api and custom role api which have no parameters

please can u tell me how to fix this issue?

Retrieve Token Error

I am trying to retrieve a token in Postman. The body is set to

{
  "guest": true,
  "username": "xxxxx",
  "password": "xxxx",
  "remember_me": true
}

But I get an error:

Autofac.Core.DependencyResolutionException: An exception was thrown while activating Nop.Plugin.Api.Controllers.TokenController.
 ---> Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Nop.Plugin.Api.Controllers.TokenController' can be invoked with the available services and parameters:
Cannot resolve parameter 'Nop.Plugin.Api.Configuration.ApiConfiguration apiConfiguration' of constructor 'Void .ctor(Nop.Services.Customers.ICustomerService, Nop.Services.Customers.ICustomerRegistrationService, Nop.Services.Logging.ICustomerActivityService, Nop.Services.Orders.IShoppingCartService, Nop.Services.Authentication.IAuthenticationService, Nop.Core.Domain.Customers.CustomerSettings, Nop.Plugin.Api.Domain.ApiSettings, Nop.Plugin.Api.Configuration.ApiConfiguration)'.
   at Autofac.Core.Activators.Reflection.ReflectionActivator.GetAllBindings(ConstructorBinder[] availableConstructors, IComponentContext context, IEnumerable`1 parameters)
   at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
   at Autofac.Core.Activators.Reflection.ReflectionActivator.<ConfigurePipeline>b__11_0(ResolveRequestContext ctxt, Action`1 next)
   at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   --- End of inner exception stack trace ---
   at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request)
   at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request)
   at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
   at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
   at Microsoft.AspNetCore.Mvc.Controllers.ServiceBasedControllerActivator.Create(ControllerContext actionContext)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at WebMarkupMin.AspNetCore5.WebMarkupMinMiddleware.ProcessAsync(HttpContext context, Boolean useMinification, Boolean useCompression)
   at WebMarkupMin.AspNetCore5.WebMarkupMinMiddleware.ProcessAsync(HttpContext context, Boolean useMinification, Boolean useCompression)
   at WebMarkupMin.AspNetCore5.WebMarkupMinMiddlewareBase.Invoke(HttpContext context)
   at StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in C:\projects\dotnet\src\MiniProfiler.AspNetCore\MiniProfilerMiddleware.cs:line 104
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Nop.Services.Authentication.AuthenticationMiddleware.InvokeAsync(HttpContext context) in C:\ann\NopCommerceTest\Libraries\Nop.Services\Authentication\AuthenticationMiddleware.cs:line 94
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatch|8_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask)
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Nop.Services.Installation.InstallUrlMiddleware.InvokeAsync(HttpContext context, IWebHelper webHelper) in C:\ann\NopCommerceTest\Libraries\Nop.Services\Installation\InstallUrlMiddleware.cs:line 52
   at Nop.Services.Common.KeepAliveMiddleware.InvokeAsync(HttpContext context, IWebHelper webHelper) in C:\ann\NopCommerceTest\Libraries\Nop.Services\Common\KeepAliveMiddleware.cs:line 49
   at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

HEADERS
=======
Accept: */*
Accept-Encoding: gzip, deflate, br
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 112
Content-Type: text/plain
Cookie: .Nop.Customer=e25dcfeb-d48d-47a5-bfcc-fe83e1492a80
Host: localhost:44369
User-Agent: PostmanRuntime/7.28.4
Postman-Token: 8909b04a-4635-490f-b2a1-62079e01ddac

Picture is attached.

Any idea what I'm doing wrong. I copied your project and added it as a plugin to a test NopCommerce.


2021_08_24_22_04_19_Postman

Update nopcommerce 4.5

Is there any plan to upgrade the project to the new release of nopcommerce and .net 6?

401 Error: Unauthorized

I keep getting a 401 Error: Unauthorized trying to bring up any api endpoint. I've added myself (Admin) as an api user and guest to the customer roles. Tried limiting the access to this website. Also tried without those. I've disabled both ACL rules and limit to stores.

I did change the supporting version number from 4.40 to 4.50 to get it to work but wouldn't figure that to cause any problems.

I have clicked on the Authorize button and in the value I added: Bearer JWT

Still no results.

using ApiBindings.NopApı.DTOs;

Hi,
I could use this class as "ApiBindings.NopApı.DTOs" not ApiBindings.NopApi.DTOs;
and also still errors as the picture below.
image
How can I fix them ?

Date Parameter Issue

We are testing the API and came across an issue with dates.
We were testing both GetCustomers and GetOrders with the CreatedAtMin parameter and are seeing the same issue with both.

When we pass a date in the format specified, the property is not being parsed and is set to null. If we send the date with out the time (2008-12-31) the date is parsed with the time set to 12:00am.
///


/// Show orders created after date (format: 2008-12-31 03:00)
///

[JsonProperty("created_at_min")]
public DateTime? CreatedAtMin { get; set; }

i.e
https://localhost:44369/api/orders?status=pending&CreatedAtMin=2008-12-31 03:00

If we remove the model binder attribute from the OrdersParametersModel the datetime (2008-12-31 03:00) is parsed as expected.
[ModelBinder(typeof(ParametersModelBinder))]

It appears the model binder attribute is causing issues with datetimes.

GetToken stuck on "Pending request"

Hi, i'm building an Angular app with NopCommerce api. I've set-up nopcommerce plugin correctly and i'm able via Swagger or Postman to get the "guest" token trough a post request to /token.

But when i try to make the same call (post) trough HttpClient library of Angulat, the request stuck on "pending".

The simply code i wrote:

getGuestToken(): Observable<any> {
    let headers = new HttpHeaders({'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', 'Accept': 'text/plain',});
    let options = { headers: headers };
    return this.http.post(environment.apiUrl+'/auth/RequestToken', {guest:true, rememberMe: true}, options);
  }

it result on this:
Schermata 2022-04-15 alle 12 01 19
Schermata 2022-04-15 alle 12 01 38

If i generate a token from Swagger/Postman and attach to the "guest token" request, it works.
Any suggestion?

Thanks

Update the plugin.json file.

On latest build for nopCommerce the version number is 4.50. Will want to update the plugin.json to get this to show up on the newest build.

from:

{
  "Group": "Api",
  "FriendlyName": "Api plugin",
  "SystemName": "Nop.Plugin.Api",
  "Version": "4.4.0",
  "SupportedVersions": [ "4.40" ],
  "Author": "Nop-Templates team",
  "DisplayOrder": -1,
  "FileName": "Nop.Plugin.Api.dll",
  "Description": "This plugin is Restfull API for nopCommerce"
}

to:

{
  "Group": "Api",
  "FriendlyName": "Api plugin",
  "SystemName": "Nop.Plugin.Api",
  "Version": "4.4.0",
  "SupportedVersions": [ "4.50" ],
  "Author": "Nop-Templates team",
  "DisplayOrder": -1,
  "FileName": "Nop.Plugin.Api.dll",
  "Description": "This plugin is Restfull API for nopCommerce"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.