-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathodata.html
More file actions
50 lines (46 loc) · 2.17 KB
/
odata.html
File metadata and controls
50 lines (46 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
getdata();
});
function getdata() {
$.ajax({
type: 'GET',
// TODO: Your URL will be different to the one below.
url: "https://api.businesscentral.dynamics.com/v2.0/privatekey/id/ODataV4/Company('companyid')/ItemLedgerEntries",
dataType: 'json',
// As CORS is used, this must be set to true
crossDomain: false,
// Basic authentication is set in the header, enter appropriate user name and password for your environment.
// The xhr (XMLHttpRequest) function below sends authorization details to the server.
// This line creates a hash of the user name and password:
// window.btoa(unescape(encodeURIComponent("[USERNAME]" + ':' + "[PASSWORD]")))
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Basic ' + window.btoa(unescape(encodeURIComponent("<username>" + ':' + "<password>"))));
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
},
// On success, we write a 'success' message to the console and stringify the returned JSON to display,
// for example, in the <div id="t1"><div> tag on a web page
success: function (json_data) {
console.log('success');
$("#apiResponse").html(JSON.stringify(json_data));
},
// In case of error, show an alert
error: function () {
alert('Failed!');
}
})
}
</script>
</head>
<body>
<h1>Odata Api Response</h1>
<h4>API URL and credentials hardcoded in the ajax call</h4>
<label for="apiResponse">Response:</label>
<br>
<textarea id="apiResponse" name="apiResponse" rows="30" cols="50" style="width: 90%;"></textarea>
</body>
</html>