Giter VIP home page Giter VIP logo

Comments (11)

poyker avatar poyker commented on July 26, 2024

Hi @RazaMemon

Please note that the Images and the Tags are collections and also the names should be in plural.
The easiest way to see how your JSON should be structured is to make a GET request and see the returned JSON. I personally use Swagger when I want to quickly see the JSON format.
So instead of passing a single image object you need to pass a list of image objects.

from api-plugin-for-nopcommerce.

alirnz avatar alirnz commented on July 26, 2024

@poyker thanks alot.. just want to quickly check with you, i am also using swagger and it show images, i tried code like below for adding tags and images but both add product but not tags or images.
var product_json = new { product = new { name = "hello world product api", full_description = "description", short_description ="this is test", tags = new string[]{ "test","product","hello","world" } } };

var product_json = new { product = new { name = "hello world product api images", full_description = "description images", short_description ="this is test images", images = new { { display_order =1, src = "http://google.com/images.png”, attachment=“”, } } } };

both i tried and it added name, full_description, short_description in nopcommerce, but not either tag or image.

from api-plugin-for-nopcommerce.

poyker avatar poyker commented on July 26, 2024

Hi @RazaMemon

What is the JSON that is generated with your code?
It should be something like this:

{  
"product" : {
"name": "product name",
"images": [
        {        
          "src": "http://someimageurl"
        }
      ],
"tags": [ "tag1", "tag2" ]
}
}

You can see the JSON after you serialize the object to JSON and before the actual POST request.

from api-plugin-for-nopcommerce.

alirnz avatar alirnz commented on July 26, 2024

from api-plugin-for-nopcommerce.

poyker avatar poyker commented on July 26, 2024

@RazaMemon

Could you please check what is the exact error in the System -> Log?

from api-plugin-for-nopcommerce.

alirnz avatar alirnz commented on July 26, 2024

Thanks @poyker for prompt replying, appreciate your help, i am getting this error in log

System.ArgumentException: Cannot create an instance of Nop.Plugin.Api.Validators.TypeValidator1[System.Collections.Generic.List1[T]] because Type.ContainsGenericParameters is true. at System.RuntimeType.CreateInstanceCheckThis() at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at Nop.Plugin.Api.Validators.TypeValidator1.ValidateNestedProperty(Type propertyType, Dictionary2 value) at Nop.Plugin.Api.Validators.TypeValidator1.IsCurrentPropertyValid(Type type, Object value) at Nop.Plugin.Api.Validators.TypeValidator1.IsValid(Dictionary2 propertyValuePaires) at Nop.Plugin.Api.ModelBinders.JsonModelBinder1.ValidateValueTypes(ModelBindingContext bindingContext, Dictionary2 propertyValuePaires) at Nop.Plugin.Api.ModelBinders.JsonModelBinder`1.BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext) at System.Web.Http.ModelBinding.ModelBinderParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken) at System.Web.Http.Controllers.HttpActionBinding.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Filters.AuthorizationFilterAttribute.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ExceptionFilterResult.d__0.MoveNext()

from api-plugin-for-nopcommerce.

poyker avatar poyker commented on July 26, 2024

Hi @RazaMemon

Do you use the latest version of the plugin? This looks like some old error I have seen when the product type is not specified but this was fixed.

from api-plugin-for-nopcommerce.

alirnz avatar alirnz commented on July 26, 2024

@poyker i am using latest version, see my description file, i download the today,
Group: Api FriendlyName: Api SystemName: Nop.Plugin.Api Version: 1.0 SupportedVersions: 3.90 Author: nopCommerce/nop-templates team DisplayOrder: 1 FileName: Nop.Plugin.Api.dll Description: This plugin provides a Restful Api for connecting to your store

from api-plugin-for-nopcommerce.

poyker avatar poyker commented on July 26, 2024

@RazaMemon It turned out there was a problem validating generic type collection that was introduced during the upgrade to 3.90. That is why none of the collection properties was working during post/put requests. It is now corrected with this commit 0507ba1

from api-plugin-for-nopcommerce.

alirnz avatar alirnz commented on July 26, 2024

@poyker i am still unable to add product with images getting error
System.NullReferenceException: Object reference not set to an instance of an object. at Nop.Plugin.Api.Controllers.ProductsController.UpdateProductPictures(Product entityToUpdate, List1 setPictures) at Nop.Plugin.Api.Controllers.ProductsController.CreateProduct(Delta1 productDelta) at lambda_method(Closure , Object , Object[] ) at

from api-plugin-for-nopcommerce.

poyker avatar poyker commented on July 26, 2024

@RazaMemon

Thank you for reporting it! The picture service was not initialized. Already fixed.

from api-plugin-for-nopcommerce.

Related Issues (20)

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.