Success / error handler with read/create odata without batch Sapui5 - callback

is there any way of triggering a odata create callback , without batch request?
i use this code, but aparently it doesnt work because the odata cant handle batch request.
this.getOwnerComponent().getModel("model1").create("/entity", updateEntry , {
success: function() {
sap.m.MessageBox.success("Registered.", {
title: "success",
initialFocus: null
});
},
error: function() {
sap.m.MessageBox.error("Error ", {
title: "Error",
initialFocus: null
});
}
});

Related

How to use the Zoho Desk Invoke API (Proxy) to call the Zoho Desk Push-Data to Desk (aka Import) endpoint?

I am trying to use the Zoho Desk Invoke API (Proxy) to call the Zoho Desk Push-Data to Desk (aka Import) endpoint.
This is what my code looks like:
// Build the payload
const invokeApiRequestPayload = {
"securityContext":"edbsnc50b85a3cd964126073f50499ae29a3d6ed3c31123e535e901cdda1b2a312dc0a66c638e2beb2724fffc355faebabf1acd65c3883227c2d329d0c9f62cbbdf26ba4553375b5b11cab90c57590c6b48a3",
"requestURL":"https://desk.zoho.com.au/api/v1/channels/{{installationId}}/import",
"headers":{
"Content-Type":"application/json"
},
"postBody":{
"data":{
"tickets":[
{
"actor":{
"email":"test#gmail.com",
"name":"Tom Billy",
"extId":"NjPk2E6J83g41uDKsD6DznLzz323"
},
"subject":"testing new ticket",
"createdTime":"2022-07-24T01:13:44.419Z",
"status":"Open",
"extId":"YCdHTnu93pQbyNoyZzId"
}
],
"threads":[
{
"contentType":"text/html",
"createdTime":"2022-07-24T01:13:44.419Z",
"extId":"YGrfU6quGoDESjX5HEZM",
"extParentId":"YCdHTnu93pQbyNoyZzId",
"actor":{
"extId":"NjPk2E6J83g41uDKsD6DznLzz323",
"name":"Tom Billy",
"email":"test#gmail.com"
},
"canReply":true,
"content":"testing one two three<br>"
}
]
}
},
"connectionLinkName":"zohodesk",
"requestType":"POST",
"queryParams":{
"orgId":"7002257443"
}
};
// Generate the Hmac
const stringToHash = 'requestURL=https://desk.zoho.com.au/api/v1/channels/{{installationId}}/import&requestType=POST&queryParams={"orgId":"7002257443"}&postBody={"data":{"tickets":[{"extId":"YCdHTnu93pQbyNoyZzId","status":"Open","subject":"testing new ticket","createdTime":"2022-07-24T01:13:44.419Z","actor":{"extId":"NjPk2E6J83g41uDKsD6DznLzz323","name":"Tom Billy","email":"test#gmail.com"}}],"threads":[{"extId":"YGrfU6quGoDESjX5HEZM","extParentId":"YCdHTnu93pQbyNoyZzId","actor":{"extId":"NjPk2E6J83g41uDKsD6DznLzz323","name":"Tom Billy","email":"test#gmail.com"},"content":"testing one two three<br>","createdTime":"2022-07-24T01:13:44.419Z","canReply":true,"contentType":"text/html"}]}}&headers={"Content-Type":"application/json"}&connectionLinkName=zohodesk';
const hmac = crypto
.createHmac('sha256', 'mysecret123')
.update(stringToHash)
.digest('hex');
// The hmac created from the above code is '2aa21d41882223e2e23ad7004cfdc5a0317db5192fdff84431f0515d4f4e004b'
// Make the Invoke API request using Axios
const axiosOptions = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
hash: hmac,
},
params: {
orgId: '7002257443',
},
};
return await axios
.post(
'https://desk.zoho.com.au/api/v1/invoke',
invokeApiRequestPayload,
axiosOptions
)
.catch((error) => {
functions.logger.error(error);
throw new functions.https.HttpsError('unknown', error.message, error);
});
But I always get back Error 422 UNPROCESSABLE_ENTITY:
{
"errorCode":"UNPROCESSABLE_ENTITY",
"message":"`Extra query parameter '{\"securityContext\":\"edbsnc50b85a3cd964126073f50499ae29a3d6ed3c31123e535e901cdda1b2a312dc0a66c638e2beb2724fffc355faebabf1acd65c3883227c2d329d0c9f62cbbdf26ba4553375b5b11cab90c57590c6b48a3\",\"requestURL\":\"https://desk.zoho.com.au/api/v1/channels/{{installationId}}/import\",\"requestType\":\"POST\",\"postBody\":{\"data\":{\"tickets\":[{\"extId\":\"YCdHTnu93pQbyNoyZzId\",\"status\":\"Open\",\"subject\":\"testing new ticket\",\"createdTime\":\"2022-07-24T01:13:44.419Z\",\"actor\":{\"extId\":\"NjPk2E6J83g41uDKsD6DznLzz323\",\"name\":\"Tom Billy\",\"email\":\"test#gmail.com\"}}],\"threads\":[{\"extId\":\"YGrfU6quGoDESjX5HEZM\",\"extParentId\":\"YCdHTnu93pQbyNoyZzId\",\"actor\":{\"extId\":\"NjPk2E6J83g41uDKsD6DznLzz323\",\"name\":\"Tom Billy\",\"email\":\"test#gmail.com\"},\"content\":\"testing one two three<br>\",\"createdTime\":\"2022-07-24T01:13:44.419Z\",\"canReply\":true,\"contentType\":\"text/html\"}]}},\"headers\":{\"Content-Type\":\"application/json\"},\"queryParams\":{\"orgId\":\"7002257443\"},\"connectionLinkName\":\"zohodesk\"}' is present in the input.`"
}
The Zoho Desk docs have this explanation for the UNPROCESSABLE_ENTITY error code:
This errorCode value appears if the input does not fulfil the
conditions necessary for successfully executing the API.
And looking at the returned error message details it seems to be complaining that I have an "Extra query parameter". That does not make sense to me, because I included it as the payload required by the Zoho Desk Invoke API (Proxy).
Can anyone see what I am doing wrong?

how to send post data with inappbrowser ionic 4

I need to know how you can send data by post via inappbrowser to an external url that is a payment gateway
I am dealing with the property of ionic execute Script however I have not managed to pass the post data, I would like to see if there is another way but I need to use inappbrowser
let options: InAppBrowserOptions={
zoom:'no',clearcache:'yes',hidden:'yes',hidenavigationbuttons:'yes',hideurlbar:'yes'
};
let customheader= 'foo:123,bar:456';
const browser= this.iab.create('https://url_anyway','_blank',options);
browser.on('loadstop').subscribe( (ev: InAppBrowserEvent) => {
browser.executeScript({code: "(function() {const data = new FormData(document.getElementById('mp_account'));fetch('https://url_anyway', { method: 'POST', body: data}).then(function(response) { if(response.ok) { return response.text() } else { throw 'Error en la llamada Ajax';}}).then(function(texto) { console.log(texto);}).catch(function(err) { console.log(err);}); })()"}).then( function(){
setTimeout(function(){
browser.show();
;}, 1500);
});
});
when opening the url does not show anything by post method

Nativescript Autosync with server use REST API

Hello Nativescript user,
I have build nativescript App that get data from REST API and save to application-settings. Something like this :
fetch(config.apiUrl, {
method: 'GET',
headers: {
"X-Auth-Token": sTOKEN
}
}).then(function (response) {
return response.json();
}, function (e) {
console.log("Error occurred " + e);
})
.then(function (data) {
appSettings.remove(sPARAMETER_DATA);
appSettings.setString(sPARAMETER_DATA, JSON.stringify(data.sort()));
arrayData.set('DATA', new observableArray.ObservableArray(data.sort()));
});
So, if want data uptodate must GET again.
The question : Can use this appSettings save data locally like SQLite ? And how to autosync with server use REST API JSON ?
Thanks anyway

Parse - How to insert data on parse server using REST Api using javascript?

I am integrating parse rest api to insert data on a table using jsp page. and using following code in javascript -
var headers = {
"X-Parse-Application-Id" : "myparseappid",
"X-Parse-REST-API-Key" : "myparserestapi"
};
// Variable to store data:
var userData = {
"name" : "anyname"
};
var data = JSON.stringify(userData);
// Send data:
$.ajax({
type : "POST",
url : "https://api.parse.com/1/classes/MyClassName",
data : userData,
contentType : "application/json",
headers : headers,
dataType:"json",
success : function(data, status, xhr) {
alert("data:" + JSON.stringify(data) + " status: "+ status);
if (status === "success") {
// Show success feedback:
alert("Data was saved successfully");
} else {
// Show error message:
alert("Your data didn't save. Please check that you are online. Status: "
+ status);
}
},
error : function(data, status, xhr) {
// Show error message:
alert("Your data didn't save. Please check that you are online. Status: "
+ status);
}
});
and for ajax i called following js -
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
Question - It is not saving the records whats wrong with above code. please suggest me?
Thanks in advance!

How to serve 404's using AngularJS and a RESTful API

Let's say you have an AngularJS application hooked up to a RESTful API and you have a route for "/item/:itemId".
.when('/item/:itemId', {
templateUrl: '/static/partials/item-detail.html',
controller: ItemDetailController
})
angular.module('angServices', ['ngResource']).factory('Item', function($resource) {
return $resource('/api/item/:itemId', {}, {
query: { method: 'GET', params: { itemId: '' }, isArray: true }
});
});
If the user goes to "/item/9" and an object with the itemId 9 does not exist, Angular will receive a 404 from the API, but will not naturally return a 404 to the user.
In other questions, I've seen people suggest creating an interceptor and having Angular redirect to a 404 error page when a resource is not found.
var interceptor = ['$rootScope', '$q', function(scope, $q) {
...
function error(response) {
if (response.status == 404) { window.location = '/404'; }
...
$httpProvider.responseInterceptors.push(interceptor);
However, I want to return a correct 404 with the original requested URL for SEO purposes.
Also, the solution above first loads the page and then redirects (just like Twitter used to do), so its sub-optimal.
Should I check server-side to first see if the resource exists before passing the request on to the Angular app? The downside of this is that it wouldn't work for broken links within the application.
What is the best way to approach this?
Maybe this jsfiddle can help you.
http://jsfiddle.net/roadprophet/VwS2t/
angular.module('dgService', ['ngResource']).factory("DriveGroup", function ($resource) {
return $resource(
'/', {}, {
update: {
method: 'PUT'
},
fetch: {
method: 'GET',
// This is what I tried.
interceptor: {
response: function (data) {
console.log('response in interceptor', data);
},
responseError: function (data) {
console.log('error in interceptor', data);
}
},
isArray: false
}
}
);
});
var app = angular.module('myApp', ['ngResource', 'dgService']);
app.controller('MainController', ['$scope', 'DriveGroup', function ($scope, svc) {
$scope.title = 'Interceptors Test';
svc.fetch(function (data) {
console.log('SUCCESS');
}, function () {
console.log('FAILURE');
});
}]);
I tried with this and works fine. I only change the fetch method to get.
In your case, you will need to change the console.log('FALIURE'); to $location.path('/404');.
GL!