POST data to API


#1

Hi, Been trying to post some data to an API located here https://api.beds24.com/json/createProperties

I think I have the code right as I am not getting any errors and the console logs look ok (not that I know for sure) but the data is not getting posted Could someone look over the code and log to see if I am missing something obvious, API’s are new to me so I could be missing something. Thanks for looking.

Code:

<html>
<head>
<meta charset="UTF-8"> 
<title> Ajax and Json | Tutorial</title>
</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 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': '*',
					//'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE',
					//'Access-Control-Allow-Headers': 'Content-Type, Authorization',
					//'content-type': 'application/json; charset=UTF-8'
					//"apiKey": "123456789101112131415167"
					},

		url:"https://api.beds24.com/json/createProperties?",
		method:"POST",
		dataType: 'json',

		data: {

		
		

"authentication": {
    "apiKey": "123456789101112131415167"
},
"createProperties": [
    {
        "name": "New Hotel 1",
        "propKey": "YourKeyToUseForTheNewHotel1",
        "notifyUrl": "http:\/\/www.newhotel1.com\/api\/newbookings",
        "roomTypes": [
            {
                "name": "Room 1",
                "qty": "1",
                "minPrice": "0.00"
            },
            {
                "name": "Room 2",
                "qty": "3",
                "minPrice": "0.00"
            }
        ]
    },
    {
        "name": "New Property 2",
        "propKey": "YourKeyToUseForThepropIdNewProperty2",
        "notifyUrl": "http:\/\/www.newproperty2.com\/api\/index.php?action=updatebooking",
        "roomTypes": [
            {
                "name": "Camp Site",
                "qty": "10",
                "minPrice": "0.00"
            },
            {
                "name": "Cabin",
                "qty": "2",
                "minPrice": "0.00"
            }
        ]
    }
]
		
		
		
		
		},
		
		
	})
}


</script>
</body>
</html>

Console response:

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
Access-Control-Allow-Origin: *
Connection: Keep-Alive
Content-Length: 56
Content-Type: application/json
Date: Sat, 15 Sep 2018 09:48:29 GMT
Keep-Alive: timeout=5, max=100
Server: Apache
Provisional headers are shown
Accept: application/json, text/javascript, */*; q=0.01
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Origin: http://localhost:8081
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
authentication[apiKey]: 123456789101112131415167
createProperties[0][name]: New Hotel 1
createProperties[0][propKey]: YourKeyToUseForTheNewHotel1
createProperties[0][notifyUrl]: http://www.newhotel1.com/api/newbookings
createProperties[0][roomTypes][0][name]: Room 1
createProperties[0][roomTypes][0][qty]: 1
createProperties[0][roomTypes][0][minPrice]: 0.00
createProperties[0][roomTypes][1][name]: Room 2
createProperties[0][roomTypes][1][qty]: 3
createProperties[0][roomTypes][1][minPrice]: 0.00
createProperties[1][name]: New Property 2
createProperties[1][propKey]: YourKeyToUseForThepropIdNewProperty2
createProperties[1][notifyUrl]: http://www.newproperty2.com/api/index.php?action=updatebooking
createProperties[1][roomTypes][0][name]: Camp Site
createProperties[1][roomTypes][0][qty]: 10
createProperties[1][roomTypes][0][minPrice]: 0.00
createProperties[1][roomTypes][1][name]: Cabin
createProperties[1][roomTypes][1][qty]: 2
createProperties[1][roomTypes][1][minPrice]: 0.00

#2

The data being returned to you indicates the server received the data correctly.
Verify your API keys, and contact the API host to inquire as to why it isn’t processing.