Hi, I am using the following code trying to POST / add some property data through using this code https://api.beds24.com/json/createProperties and I am getting no errors and the console response looks ok (but I have very limited JSON API knowledge. Please could someone have a look and point me in the right direction. Thanks for looking.
Here is my code.
<html>
<head>
<meta charset="UTF-8">
<title> Ajax and Json | Tutorial</title>
<style>
body{
font-family: sans-serif;
}
.ajax-container{
width: 50%;
margin: 50px auto;
}
#btnAjaxCall{
height: 50px;
width: 120px;
border: none;
border-radius: 6px;
color: white;
background: #3498db;
outline: none;
font-size: 22px;
opacity: 0.7;
padding: 10px;
}
#btnAjaxCall:hover{
cursor: pointer;
opacity: 1;
}
.item-details{
margin-top: 10px;
border: 1px solid #ddd;
padding: 6px;
}
</style>
</head>
<body>
<form method=post>
<div class="ajax-container">
<input type="button" id="btnAjaxCall" value="Ajax Call" />
<div class="display-data">
</div>
</div>
</form>
<script type="text/javascript" src="/sample5/js/jquery-3.3.1.min.js"></script>
<!--<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>-->
<script>
var count = 0;
$("#btnAjaxCall").click(function(){
fetchDataAndDisplay();
});
function fetchDataAndDisplay(){
$.ajax({
headers: {
'content-type': 'application/x-www-form-urlencoded',
//'Access-Control-Allow-Origin': 'http://localhost:8081',
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
url:"https://api.beds24.com/json/createProperties",
method:"POST",
dataType: 'json',
data: {
"authentication": {
"apiKey": "12345678910112344567898"
},
"createProperties": [
{
"name": "White house1",
"propKey": "2222222222233333",
"notifyUrl": "http:\/\/www.White1.com\/api\/newbookings",
"roomTypes": [
{
"name": "White 1xx",
"qty": "1",
"minPrice": "10.00"
},
{
"name": "White 2xx",
"qty": "3",
"minPrice": "10.00"
}
]
},
{
"name": "New Property 2",
"propKey": "2222222222244444",
"notifyUrl": "http:\/\/www.White2.com\/api\/index.php?action=updatebooking",
"roomTypes": [
{
"name": "White Sitex",
"qty": "10",
"minPrice": "10.00"
},
{
"name": "White 1",
"qty": "2",
"minPrice": "10.00"
}
]
}
]
},
})
}
</script>
</body>
</html>
Here is the console response to the request.
- Request URL:
https://api.beds24.com/json/createProperties
- Request Method:
POST
- Status Code:
200 OK
- Remote Address:
195.201.74.20:443
- Referrer Policy:
no-referrer-when-downgrade
-
Response Headers
-
Access-Control-Allow-Headers:
access-control-allow-headers,access-control-allow-methods
- Access-Control-Allow-Methods:
POST, GET, OPTIONS, PUT, DELETE
-
Access-Control-Allow-Origin:
-
Allow:
POST, GET, OPTIONS, PUT, DELETE
- Connection:
Keep-Alive
- Content-Length:
56
- Content-Type:
application/json
- Date:
Wed, 05 Sep 2018 10:43:07 GMT
- Keep-Alive:
timeout=5, max=99
- Server:
Apache
-
Request Headers
-
Provisional headers are shown
-
Accept:
application/json, text/javascript, /; q=0.01
- Access-Control-Allow-Headers:
Content-Type, Authorization
- Access-Control-Allow-Methods:
GET,PUT,POST,DELETE
- Content-Type:
application/x-www-form-urlencoded
- Origin:
- Referer:
http://localhost:8081/sample5/getajax_bed24v2.html
- User-Agent:
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
-
Form Dataview sourceview URL encoded
-
authentication[apiKey]:
12345678910111213141516
- createProperties[0][name]:
White house1
- createProperties[0][propKey]:
2222222222233333
- createProperties[0][notifyUrl]:
http://www.White1.com/api/newbookings
- createProperties[0][roomTypes][0][name]:
White 1xx
- createProperties[0][roomTypes][0][qty]:
1
- createProperties[0][roomTypes][0][minPrice]:
10.00
- createProperties[0][roomTypes][1][name]:
White 2xx
- createProperties[0][roomTypes][1][qty]:
3
- createProperties[0][roomTypes][1][minPrice]:
10.00
- createProperties[1][name]:
New Property 2
- createProperties[1][propKey]:
2222222222244444
- createProperties[1][notifyUrl]:
http://www.White2.com/api/index.php?action=updatebooking
- createProperties[1][roomTypes][0][name]:
White Sitex
- createProperties[1][roomTypes][0][qty]:
10
- createProperties[1][roomTypes][0][minPrice]:
10.00
- createProperties[1][roomTypes][1][name]:
White 1
- createProperties[1][roomTypes][1][qty]:
2
- createProperties[1][roomTypes][1][minPrice]:
10.00