How to do a service call for 'POST' method for the payload with the headers described below?
Payload for the service:
{
"SupplierPOPrint": {
"ErrorFlag": "Status Code: 20, Message ID: 505",
"ResultMessage": "Integration Service: Unable to find a routing corresponding to the incoming request message."
}
}
headers: { "Accept": "application/json", "Content-Type": "text/xml", },
function poPrint() {
$.ajax({
url: '/wps/proxy/http/10.249.114.31:8009/soa-infra/resources/SupplierPortal/CreateSupplierPOPrintService!1.0/CreateSupplierPOPrintService/Create',
type: 'POST',
dataType: 'json',
data: new XMLSerializer().serializeToString(updatedTemplate),
crossDomain: true,
success: function(poPrintData) {
console.log("poPrintData", poPrintData);
poPrintDetails = poPrintData.SupplierPOPrint;
console.log("poPrintDetails", poPrintDetails);
poPrintTemplate = generatepoPrint(poPrintData);
$("#poPrintOutput").html(poPrintTemplate);
},
error: function(data) {
console.log("Update Content Failed", data);
}
});
}
Related
I have below code for post request but 422 error is shown:
$.ajax({
url: 'https://napi.arvancloud.com/vod/2.0/channels/166c3942-4e8d-4ab7-a543-c46e4528bf08/videos',
headers: {
'Authorization': authorization,
'Accept-Language': "en"
},
data: new FormData(document.forms[0]),
contentType: false,
processData: false,
type: 'post',
success: function() {
alert('Uploaded by jQuery');
}
})
$.ajax({
url: 'https://napi.arvancloud.com/vod/2.0/channels/166c3942-4e8d-4ab7-a543-c46e4528bf08/videos',
headers: {
'Authorization': authorization,
'Accept-Language': "en"
},
data: new FormData(document.forms[0]),
contentType: false,
processData: false,
type: 'post',
success: function () {
alert('Uploaded by jQuery');
}
})
});
})
I am a beginner to programming and for a challenge I need to get the status (Streaming live/Off-line) for a given number of channels.
I wrote an ajax request but I am still getting 401 as a response. Below my code and a screen shot of the response.
I have even made the token request as async: falseto make sure the token is back before triggering the API call
$("document").ready(function() {
var aoathToken = $.ajax({
type: "POST",
url: "https://id.twitch.tv/oauth2/token?client_id=MYCLIENTID&client_secret=MYSECRET&grant_type=client_credentials",
error: function() {
console.log("Check your request!!")
},
success: function(token) {
console.log(token);
}
})
$.ajax({
type: "GET",
url: "https://api.twitch.tv/helix/streams?user_id=freecodecamp",
contentType: ('application/x-www-form-urlencoded; charset=UTF-8'),
crossDomain: true,
header: {
"Access-Control-Allow-Origin": "*",
"Client-ID": "MY CLIENT ID",
"Authorization": "Bearer " + aoathToken,
},
data: {"user_login": "myUserID"},
dataType: "json",
success: function(json) {
console.log(JSON.stringify(json, null, 2));
},
error: function(json) {
window.alert(json.status + " " + json.message);
},
})
i got my json string inside the ajax as function like this way
$.ajax({
type: "POST",
url: "http://localhost/./Service/GetPageInfo",
dataType: "json",
contentType: 'application/json',
data: JSON.stringify({
filename: filename
}),
success: function (data) {
alert('Success');
},
error: function () {
alert('Error');
}
});
here i get data like
[{"main":{"sub":[],"tittle":"manu","startvalue":"","stopvalue":"","status":"","accumalated":"","comment":""}}]
i want it in a variable like
var myjsonobject =[{"main":{"sub":[],"tittle":"manu","startvalue":"","stopvalue":"","status":"","accumalated":"","comment":""}}]
There you go :
$.ajax({
type: "POST",
url: "http://localhost/./Service/GetPageInfo",
dataType: "json",
contentType: 'application/json',
data: JSON.stringify({
filename: filename
}),
success: function (data) {
alert('Success');
var jsonobject = data;
},
error: function () {
alert('Error');
}
});
Also I strongly advise you to use promises to make API calls: https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Promise
var jsonobject= null;
$.ajax({
type: "POST",
url: "http://localhost/./Service/GetPageInfo",
dataType: "json",
contentType: 'application/json',
data: JSON.stringify({
filename: filename
}),
success: function (data) {
jsonobject=data;
alert('Success');
},
error: function () {
alert('Error');
}
});
If you want wait for ajax response and fill up variable then pass async: false in ajax request options.
Based on your comment, you need to parse the JSON in your success handler,
success: function (data) {
alert('Success');
var myjsonobject = JSON.parse( data );
},
I want to send an AJAX call to a service with a couple of custom headers. While the request goes successfully, the headers are not being sent. The following is my code snippet:
func123: function (params) {
return $.ajax({
url: "http://localhost:8080/",
type: 'GET',
headers: {
"Contract": "1",
"Vector": "abc",
"Authorization": "xyz"
},
dataType: 'json',
contentType: 'application/json'
});
},
I have been trying to send an email to the sharepoint user on click of a button in a client side web page.
I am trying to use the REST API using JSOM
and the code looks like below.
sendEmail("user#domain.com", "rec#domain.com", "test", "test-email");
function sendEmail(from, to, body, subject) {
var siteurl = _spPageContextInfo.webServerRelativeUrl;
var urlTemplate = siteurl + "/_api/SP.Utilities.Utility.SendEmail";
$.ajax({
contentType: 'application/json',
url: urlTemplate,
type: "POST",
data: JSON.stringify({
'properties': {
'__metadata': { 'type': 'SP.Utilities.EmailProperties' },
'From': from,
'To': { 'results': [to] },
'Body': body,
'Subject': subject
}
}
),
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
alert("Eposten ble sendt");
},
error: function (err) {
alert(err.responseText);
debugger;
}
});
}
The issue what am facing here is:
1. Am getting an error 404 Not Found => does it mean my server does not have the utilities api?
2. When i tried (siteurl + "/_api/SP.Utilities.Utility.SendEmail") in browser it gives 404 not found.
Let me know how to resolve this issue.(Note: i dont have access to central admin).
(or)
Is there any other way to send an email without using workflow? or to call an workflow from a script?
Add following code to send E-Mail through Rest API in SharePoint.
Code get from this Link
$.ajax({
contentType: 'application/json',
url: urlEmail,
type: "POST",
data: JSON.stringify({
'properties': {
'__metadata': { 'type': 'SP.Utilities.EmailProperties' },
'Body': 'Lorem ipsum dolor sit amet...',
'To' : { 'results': ['admin#codeplayandlearn.com'] },
'Subject': "E-Mail From REST API";
}
}),
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
alert("Email Send Successful.");
},
error: function (err) {
alert(err.responseText);
}
});