Dan,
the  version is 1.5.3.

I still have to learn about preparing the case for online access.

But at least i have what was sent by the server, below.

For your information, I tried to ommit the 'value' here, but again,
that error "Status: 422 "invalidReason": "No 'value' key"" appears.


Stefano,

i tried $http.post([url], data) and curiously it worked.

However i still need to base on $resource, because my app requires
offline access (brought by a third-party module, that is a $resource
drop-in replacement).

Thanks for your help,
----

Server response:
"
{data: {…}, status: 422, config: {…}, statusText: "Unprocessable
Entity", headers: ƒ}
config:
    data:
    __proto__:Object
headers:
    Accept:"application/json, text/plain, */*"
    Authorization:"Basic ZG9tYWluYXBwLWFkbWluOnBhc3M="
    Content-Type:"application/json;charset=utf-8"
__proto__:Object
method:"POST"
paramSerializer:ƒ ngParamSerializer(params)
    arguments:(...)
    caller:(...)
    length:1
    name:"ngParamSerializer"
prototype:{constructor: ƒ}
__proto__:ƒ ()
[[FunctionLocation]]:ionic.bundle.js:23581
[[Scopes]]:Scopes[2]
params:
    asset:
        value:
        href:"http://localhost:8080/restful/objects/businessentities.Asset/52";
        __proto__:Object
    __proto__:Object
    audit:
        value:
        href:"http://localhost:8080/restful/objects/businessentities.Audit/2";
        __proto__:Object
    __proto__:Object
    location:
        value:
        
href:"http://localhost:8080/restful/objects/businessentities.Location/46";
        __proto__:Object
    __proto__:Object
__proto__:Object
transformRequest:[ƒ]
transformResponse:[ƒ]
url:"http://localhost:8080/restful/services/domainapp.dom.BusinessEntities.AuditItemMenu/actions/create/invoke";
__proto__:Object
data:
asset:
    invalidReason:"Expected a link (because this object's type is not
a value) but found no 'href'"
    
value:"{"value":{"href":"http://localhost:8080/restful/objects/businessentities.Asset/52"}}";
    __proto__:Object
audit:
    invalidReason:"Expected a link (because this object's type is not
a value) but found no 'href'"
    
value:"{"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:"{"value":{"href":"http://localhost:8080/restful/objects/businessentities.Location/46"}}";
    __proto__:Object
    x-ro-invalidReason:"Mandatory"
__proto__:Object
headers:ƒ (name)
arguments:(...)
caller:(...)
length:1
name:""
prototype:{constructor: ƒ}
__proto__:ƒ ()
[[FunctionLocation]]:ionic.bundle.js:23738
[[Scopes]]:Scopes[3]
status:422
statusText:"Unprocessable Entity"
__proto__:Object
"



2017-09-11 5:38 GMT-04:00, Stefano Cascarini <[email protected]>:
> How about trying
>
> $http.post("
> http://localhost:8080/restful/services/domainapp.dom.BusinessEntities.AuditItemMenu/actions/create/invoke";,
> data)
>
> At the moment you're sending the data as url parameters rather than as a
> body.
>
>
>
>
>
> On Mon, Sep 11, 2017 at 8:00 AM, Dan Haywood <[email protected]>
> wrote:
>
>> 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
>> > >
>> >
>>
>

Reply via email to