Create, Read, Update and Delete

Overview

To execute each of these actions you need to use the appropriate request method. There are different types of request methods.
Action Request method
Create POST
Read GET
Update PUT
Delete DELETE
When a action is executed you'll receive a status and in some cases a response body.

Create

In order to create cards and documents you

  • use the request method 'POST'.
  • supply in the request url the context, namely the dossier and Venice object.
  • supply in the request header the credentials.
  • supply in the request body the data you want to insert in json or xml.

Example to create an article:
var body = '\
<?xml version="1.0" ?>\
<Request>\
  <Articles>\
    <Article>\
	  <Fields>\
		<Number>AB1234</Number>\
		<DscLng1>Wooden table</DscLng1>\
		<SalesPrice>1299.00</SalesPrice>\
	  </Fields>\
    </Article>\
  </Articles>\
</Request>';

request = new XMLHttpRequest();
request.open("POST", "https://ponte.venice.be/webconnect/api/Demo/Article", false);
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Authorization", "Basic " + Base64.encode ("User:Password"));
request.setRequestHeader("Content-Type", "application/xml");
request.onreadystatechange = function () {
	if (request.readyState == 4) { // Request finished and response is ready.
		if (request.status == 200) { // Status: OK
			console.log("Create succeeded.");
		} else {
			console.log(request.status);
		}
	}
}
request.send(body);

Read

In order to get one or more items of a Venice object you

  • use the request method 'GET'.
  • supply in the request url the context (dossier), the key to use, and the fields to return.
  • supply in the request header the credentials and the format of the response body.

Example to get 1 article with key 'Number' and value 'MyArticle':
request = new XMLHttpRequest();
request.open("GET", "https://ponte.venice.be/webconnect/api/Demo/Article?Number=MyArticle", false);
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Authorization", "Basic " + Base64.encode ("User:Password"));
request.onreadystatechange = function () {
	if (request.readyState == 4) { // Request finished and response is ready.
		if (request.status == 200) { // Status: OK
			console.log(request.responseText);
		} else {
			console.log(request.status);
		}
	}
}
request.send();

Update

In order to modify Venice data you

  • use the request method 'PUT'.
  • supply in the request url the context (dossier).
  • supply in the request header the credentials and the format (json or xml) of the body.
  • supply in the request body the data you want to update.

Example to update the SalesPrice to 1500,00 euro of article with key 'Number' and value 'MyArticle'.
var body = '\
<?xml version="1.0" ?>\
<Request>\
  <Articles>\
    <Article>\
	  <Fields>\
		<SalesPrice>1500.00</SalesPrice>\
	  </Fields>\
    </Article>\
  </Articles>\
</Request>';

request = new XMLHttpRequest();
request.open("PUT", "https://ponte.venice.be/webconnect/api/Demo/Article?number=MyArticle", false);	
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Authorization", "Basic " + Base64.encode ("User:Password"));
request.setRequestHeader("Content-Type", "application/xml");
request.onreadystatechange = function () {
	if (request.readyState == 4) { // Request finished and response is ready.
		if (request.status == 200) { // Status: OK
			console.log("Update succeeded.");
		} else {
			console.log(request.status);
		}
	}
}
request.send(body);

Delete

In order to delete a card or document you

  • use the request method 'DELETE'.
  • supply in the request url the context (dossier), the identification of the record with a key and a value.
  • supply in the request header the credentials and the format (json or xml) of the body.

Example to delete an article with number 'MyArticle':
request = new XMLHttpRequest();
request.open("DELETE", "https://ponte.venice.be/webconnect/api/Demo/Article?number=MyArticle", false);
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Authorization", "Basic " + Base64.encode ("User:Password"));
request.onreadystatechange = function () {
	if (request.readyState == 4) { // Request finished and response is ready.
		if (request.status == 200) { // Status: OK
			console.log("Delete succeeded.");
		} else {
			console.log(request.status);
		}
	}
}
request.send();

Http status

In order to know if a request was successfully executed, you have to check the status.
Code Name Description
200 OK The action has been successfully executed.
204 NoContent The request has been successfully processed, but the response is intentionally blank.
404 NotFound The requested card(s) or document(s) could not be found.
500 InternalServerError A generic error has occurred on the server. Check the error message for more information.
503 ServiceUnavailable Indicates that the server is temporarily unavailable, usually due to high load or maintenance.

Response

In case of a successful GET request you'll find the data in a response body in the format (json or xml) you've asked for. The data is structured in the same way as in the request body. If a request wasn't successful, you'll potentially get a html text with more info about the error.

Multiple items

If multiple items are requested, the call succeeds if at least one item has been found. Each item in the response, will appear in the same order as reqested. Items that were not found appear as empty items in the json or xml.