Hi Eder, sorry no-one has come back with a quick solution for you ... I guess we don't have too many Angular JS experts reading.
To confirm, is this Angular JS (or v1.x) rather than Angular (V2+) ? If you could upload to github a simple example with Angular JS code that demonstrates the issue, I'll see if I can take a look. Also, done it works with Postman, perhaps you could use Fiddler or just the Chrome/Firefox debugging tools to see what is being sent over the wire? It's also very easy to debug servers use, so you could put a breakpoint in the appropriate XxxServerSideResource class to see what's being received in the Postman Vs Angular cases. HTH Dan On Sat, 9 Sep 2017, 02:13 L Eder <[email protected]> wrote: > What i am doing wrong or missing? > > Could someone give a tip on AngularJS for when invoking a create > (POST) action ? > > I have currently this use case, and it works when the API method all > args are by-value. > > However when the args are by-reference (object reference), i am unable > to succeed it using AngularJS. But i succeed if i do it using Postman. > > The message i am getting is: > > "Expected a link (because this object's type is not a value) but > found no 'href'" > > Thanks in advance, Eder > > > > = Source Code on backend = > AuditItemMenu.java: > @Action( > ) > @MemberOrder(sequence = "3") > public AuditItem create( > final Audit audit, > final Asset asset, > final Location location) { > return auditItemrepository.create(audit, asset, location); > } > > > = Source Code on frontend = > > .factory('AuditItemStore', function($http, $ionicLoading, $resource) { > var apiUrl = 'http://localhost:8080'; > > // Define a resource > var AuditItemCreate = $resource( > apiUrl + > '/restful/services/domainapp.dom.BusinessEntities.AuditItemMenu/actions/create/invoke'); > > var list = function() { > > var pendingWrites = []; > > return pendingWrites; > } > > var create = function(auditItem) { > > var data = { > "location" : { > "href" : > "http://localhost:8080/restful/objects/businessentities.Location/47" > }, > "asset" : { > "href": > "http://localhost:8080/restful/objects/businessentities.Asset/36" > }, > "audit" : { > "href" : > "http://localhost:8080/restful/objects/businessentities.Audit/2" > } > } > > // Post the new data > var a2 = new AuditItemCreate(); > > a2.$save(data) > .then(function(res) { console.log("success") }) > .catch(function(req) { console.log("error saving obj: " + > JSON.stringify(req, null, 4)); }) > .finally(function() { console.log("always called") }); > }; > > > = Error result, as displayed by Chrome Developer Tools console = > > POST > http://localhost:8080/restful/services/domainapp.dom.BusinessEntities.AuditItemMenu/actions/create/invoke?asset=%7B%22href%22:%22http:%2F%2Flocalhost:8080%2Frestful%2Fobjects%2Fbusinessentities.Asset%2F36%22%7D&audit=%7B%22href%22:%22http:%2F%2Flocalhost:8080%2Frestful%2Fobjects%2Fbusinessentities.Audit%2F2%22%7D&location=%7B%22href%22:%22http:%2F%2Flocalhost:8080%2Frestful%2Fobjects%2Fbusinessentities.Location%2F47%22%7D > 422 (Unprocessable Entity) > > audititemstore.js:60 error saving obj: > { > "data": { > "asset": { > "value": > "{\"href\":\" > http://localhost:8080/restful/objects/businessentities.Asset/36\"}", > "invalidReason": "Expected a link (because this object's > type is not a value) but found no 'href'" > }, > "audit": { > "value": > "{\"href\":\" > http://localhost:8080/restful/objects/businessentities.Audit/2\"}", > "invalidReason": "Expected a link (because this object's > type is not a value) but found no 'href'" > }, > "location": { > "value": > "{\"href\":\" > http://localhost:8080/restful/objects/businessentities.Location/47\"}", > "invalidReason": "Expected a link (because this object's > type is not a value) but found no 'href'" > }, > "x-ro-invalidReason": "Mandatory" > }, > "status": 422, > "config": { > "method": "POST", > "transformRequest": [ > null > ], > "transformResponse": [ > null > ], > "data": {}, > "url": " > http://localhost:8080/restful/services/domainapp.dom.BusinessEntities.AuditItemMenu/actions/create/invoke > ", > "params": { > "location": { > "href": > "http://localhost:8080/restful/objects/businessentities.Location/47" > }, > "asset": { > "href": > "http://localhost:8080/restful/objects/businessentities.Asset/36" > }, > "audit": { > "href": > "http://localhost:8080/restful/objects/businessentities.Audit/2" > } > }, > "headers": { > "Accept": "application/json, text/plain, */*", > "Authorization": "Basic ZG9tYWluYXBwLWFkbWluOnBhc3M=", > "Content-Type": "application/json;charset=utf-8" > } > }, > "statusText": "Unprocessable Entity" > } > > > > > NOTE: > > If i change the args, by adding 'value' in the JSON string, i still > get the same error: > > var data = { > "location": { > "value": { > "href": > "http://localhost:8080/restful/objects/businessentities.Location/47" > } > }, > "asset": { > "value": { > "href": > "http://localhost:8080/restful/objects/businessentities.Asset/36" > } > }, > "audit": { > "value": { > "href": > "http://localhost:8080/restful/objects/businessentities.Audit/2" > } > } > } > > > > POST > http://localhost:8080/restful/services/domainapp.dom.BusinessEntities.AuditItemMenu/actions/create/invoke?asset=%7B%22value%22:%7B%22href%22:%22http:%2F%2Flocalhost:8080%2Frestful%2Fobjects%2Fbusinessentities.Asset%2F36%22%7D%7D&audit=%7B%22value%22:%7B%22href%22:%22http:%2F%2Flocalhost:8080%2Frestful%2Fobjects%2Fbusinessentities.Audit%2F2%22%7D%7D&location=%7B%22value%22:%7B%22href%22:%22http:%2F%2Flocalhost:8080%2Frestful%2Fobjects%2Fbusinessentities.Location%2F47%22%7D%7D > 422 (Unprocessable Entity) > audititemstore.js:60 error saving obj: > { > "data": { > "asset": { > "value": > "{\"value\":{\"href\":\" > http://localhost:8080/restful/objects/businessentities.Asset/36\"}}", > "invalidReason": "Expected a link (because this object's > type is not a value) but found no 'href'" > }, > "audit": { > "value": > "{\"value\":{\"href\":\" > http://localhost:8080/restful/objects/businessentities.Audit/2\"}}", > "invalidReason": "Expected a link (because this object's > type is not a value) but found no 'href'" > }, > "location": { > "value": > "{\"value\":{\"href\":\" > http://localhost:8080/restful/objects/businessentities.Location/47\"}}", > "invalidReason": "Expected a link (because this object's > type is not a value) but found no 'href'" > }, > "x-ro-invalidReason": "Mandatory" > }, > "status": 422, > "config": { > "method": "POST", > "transformRequest": [ > null > ], > "transformResponse": [ > null > ], > "data": {}, > "url": " > http://localhost:8080/restful/services/domainapp.dom.BusinessEntities.AuditItemMenu/actions/create/invoke > ", > "params": { > "location": { > "value": { > "href": > "http://localhost:8080/restful/objects/businessentities.Location/47" > } > }, > "asset": { > "value": { > "href": > "http://localhost:8080/restful/objects/businessentities.Asset/36" > } > }, > "audit": { > "value": { > "href": > "http://localhost:8080/restful/objects/businessentities.Audit/2" > } > } > }, > "headers": { > "Accept": "application/json, text/plain, */*", > "Authorization": "Basic ZG9tYWluYXBwLWFkbWluOnBhc3M=", > "Content-Type": "application/json;charset=utf-8" > } > }, > "statusText": "Unprocessable Entity" > } > --------- > > 2017-09-01 14:01 GMT-04:00, L Eder <[email protected]>: > > Hello members: > > > > Could any one shed a light on this issue? > > > > I successful run this POST request using Postman: > > JSON body > > " > > { > > "location" : { > > "value" : { "href": > > "http://localhost:8080/restful/objects/businessentities.Location/46" } > > }, > > "asset" : { > > "value" : { "href": > > "http://localhost:8080/restful/objects/businessentities.Asset/36" } > > }, > > "audit" : { > > "value" : { "href": > > "http://localhost:8080/restful/objects/businessentities.Audit/2" } > > } > > } > > " > > > > However on javascript: > > " > > var data = { > > "location" : { > > "href" : > > "http://localhost:8080/restful/objects/businessentities.Location/47" > > }, > > "asset" : { > > "href": > > "http://localhost:8080/restful/objects/businessentities.Asset/36" > > }, > > "audit" : { > > "href" : > > "http://localhost:8080/restful/objects/businessentities.Audit/2" > > } > > } > > > > // Post the new data > > var a2 = new AuditItemCreate(); > > a2.$save(data); > > ... > > " > > > > i am getting this failure (as displayed by chrome developer tools): > > " > > data: > > asset: > > invalidReason:"Expected a link (because this object's type is not a > > value) but found no 'href'" > > value:"{"href":" > http://localhost:8080/restful/objects/businessentities.Asset/36"}" > > __proto__:Object > > audit: > > invalidReason:"Expected a link (because this object's type is not a > > value) but found no 'href'" > > value:"{"href":" > http://localhost:8080/restful/objects/businessentities.Audit/2"}" > > __proto__:Object > > location: > > invalidReason:"Expected a link (because this object's type is not a > > value) but found no 'href'" > > value:"{"href":" > http://localhost:8080/restful/objects/businessentities.Location/47"}" > > __proto__:Object > > x-ro-invalidReason:"Mandatory" > > " > > > > What is wrong in this javascript code? > > > > Thank you very much, Eder > > >
