OData version4 deep insert - odata

I am trying to find out how to deep insert in odata v4. Odata v4 specification says that deep insert is possible. But I have tried it in several ways but unable to find out the solution. Whenever I am trying to post an entity with its navigation data, it is being received null on server side.
Anybody has any idea on this. Thanks

I don't know what service side do you use. However, Web API OData supports to post an entity with its navigation property.
For example, you have a Post method in your controller:
[HttpPost]
public IHttpActionResult Post(Customer customer)
{
int key = _customers.Count();
customer.Id = key + 1;
_customers.Add(customer);
return Created(customer);
}
You can issue a POST request on http://..../odata/Customers with the following sample request payload:
User-Agent: Fiddler
Host: localhost:33082
Content-Type: application/json
Content-Length: 134
{
"Id":9,
"Name":"Customer #9",
"Orders":[
{
"OrderId":2,"Price":3.3
}
]
}
Thanks.

Related

404 Bad Request Error while retrieving specific details using Swagger, But working in Postman

I have incorporated Swagger in my application. I am trying to get a individual details through id by hitting the endpoint in swagger. But I am getting the following error
Controller
#RequestMapping(value = "/{clientId}/")
public ResponseEntity<ClientDto> getClientById(#ApiParam(name = "Client Id", required = true) #PathVariable("clientId") UUID clientId){}
Error
Error Code 400
connection: close
content-length: 0
date: Tue, 22 May 2018 12:56:40 GMT
It's working correctly in Postman but I don't know why I am facing this error in swagger. Can somebody help me out from this?
I found out the reason for the issue.
The URL that I am trying to hit is
#RequestMapping(value = "/{clientId}/")
public ResponseEntity<ClientDto> getClientById(#ApiParam(name = "Client Id", required = true) #PathVariable("clientId") UUID clientId){}
I thought the name parameter in the #ApiParam is just used for display purpose in the swagger-UI but now I realized that it should match with value parameter in the #RequestMapping
I have changed the code from
#ApiParam(name="Client Id") to #ApiParam(name="clientId")

Does NOT support http GET when sending POST

tried looking around the web a bit and am at a loss.
currently setting up a REST api.
locally using postman i send the POST to the end point and all is well.
once its pushed to the test server and i run the POST
Status: 405 Method Not Allowed
{
"message": "The requested resource does not support http method 'GET'."
}
controller looks like and as said, I am able to post locally just not to test server
[HttpPost, Route("")]
[ResponseType(typeof(string))]
public async Task<IHttpActionResult> CreateSomething([FromBody] obj stuff)
c# generated by post man
var client = new RestClient("http://test-api.someurl.com/makestuff/makethisthing/");
var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "not sure if this is needed but post man put it here");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("authorization", "Bearer [A Very long OAuth token]");
request.AddHeader("content-type", "application/json");
IRestResponse response = client.Execute(request);
it works fine locally running on local iis (not iis express) on my pc and other dev pc. once put to test server then get that error message. i know i am using post as i am using postman with {{server}} env var and just changing from local to test env so the post itself is not chaining at all
there are currently a handful of other end points in separate web applications that are working fine.
any point in the right direction, thank you
Since you're sure you're requesting via POST, but the error unambiguously says you're attempting a GET, the only thing that makes sense is that there's a redirect occurring. A redirect will actually return a 301 or 302 with a Location header. The client then requests that new URL there via GET, even if the original request was a POST. In other words, the flow would be something like: POST -> 302 -> GET -> 405.
Name the action method with a specific route. E.g. /controller/create-something-post/
[HttpPost, Route("create-something-post")]
[ResponseType(typeof(string))]
public async Task<IHttpActionResult> CreateSomething([FromBody] obj stuff)
{
}

SAPUI5: sap-message not retrieved using getHeaders()

I use the functionality of mapping messages from a SAP Gateway Service to the header of the response of an OData request. This allows me to receive on the client side the messages from a backend directly in an http-header called SAP-message
Unfortunately, and although I can see the SAP-message header in the response headers of my Odata response in the Chrome Dev Tools, when using the getHeaders method of the OData Model class, this particular header is not returned
Here is the code I use:
oModel.create("/PurchaseContractHeaderCollection", mPayload, {
async : true,
success : jQuery.proxy(function(mResponse) {
// get headers
var mHeaders = this.oModel.getHeaders();
// SAP-message is not mapped in the headers of the OData model
As a result, mHeaders doesn't contain any SAP-message object
Here is the content of the response headers visible in the Chrome Dev Tools:
content-length:705
content-type:application/json; charset=iso-8859-1
dataserviceversion:2.0
location:http://<server>.<domain>/PurchaseContractHeaderCollection('xxxxxx')
sap-message:{
"code":"ME/887",
"message":"Erreur lors de la reprise des données ExtensionIn pour l'extension",
"severity":"warning","target":"",
"details":[
{"code":"BAPI/000","message":"Exception","target":"","severity":"info"},
{"code":"06/017","message":" créé(e)","target":"","severity":"info"}
]}
server:SAP NetWeaver Application Server / ABAP 731
Any idea on where the issue lies?
I got that answer from SAP:
The ODataModel.getHeaders function is only there to access the request headers which were set by the application beforehand and the ODataModel itself - You cannot access the response header via this function
Use the following code instead:
oDataModel.create(...
{success: function (oData, oResponse) {
// access response headers here: oResponse.headers
...
}});

receiving post variables from an external source in zendframework 2

i am working on a zendframework 2 project and want to receive post variables from an external source.
the source where the values will come from is a payment site (i.e world pay and paypal). i.e the return values of a payment confirming that payment has been made.
on the external site, i simply gave the URL of the web page that i want the information to be returned to:
http://example-site.com/payments/payment-made
then in action function on the controller page i did the following;
public function paymentMadeAction()
{
$contents = file_get_contents('php://input'); // read request contents
$data = explode('&', $contents);
if ($contents)
{
foreach($data as &$entry) {
$entry = explode('=', $entry);
$entry[1] = urldecode($entry[1]);
}
unset($entry);
}
print_r($data);
}
nothing happens though. i mean, i tested it but the values are not being received. when i went to the external source to check if my site received the information it confirmed that the information had been successfully sent
is there a special procedure that needs to be followed when receiving information from an external source in zend framework 2
would really appreciate any guidance or advise.
update:
below is a sample of the post variable that should be returned to the site; its a simply http object
POST /fail?installation=XXXXXX&msgType=authResult HTTP/1.0
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Host: www.worldpay.com
Content-Length: 973
User-Agent: WJHRO/1.0 (worldPay Java HTTP Request Object)
region=new+format+region&authAmountString=%26%23163%3B10.00&_SP.charEnc=UTF8&desc=&tel=&address1=new+format+address1)
you are doing it in the absolute WRONG way, the correct way to get post(or query or route ) variables in ZF2 action :
$this->params()->fromPost();
or
$this->request->getPost()->toArray();

Creating a folder in my personal Locker using Desire2Learn's REST APIs

How do I create a new folder (called "test") in my personal locker using Desire2Learn's REST API? I've tried this request, but it doesn't work:
POST /d2l/api/le/1.0/locker/mylocker/?x_a={appID}&x_c={appSig}&x_b={myUserID}&x_d={myUserSig}&x_t={time) HTTP/1.1
Host: myHost.com
Accept: */*
Content-type: application/json
{ "test" }
The server sends me back a 200 status, but also tells me "an unexpected error occurred". I've tested all the auth parameters with other routes, and they seem to work. What am I doing wrong?
This is a slightly unusual call;
The JSON data has to be just like this:
"test"
Not:
{ "test" }
There is an example in the docs of this but it is recent.

Resources