Skip to Content
2
Jun 18, 2019 at 01:50 AM

Error calling Blockchain Proof of State service from a web app

455 Views

Hi guys,

Can you please help me to call an instance of the Proof of State service from my application?

I've been following this guide to build the service. It's up and running and I don't have any problems calling it from the SAP API Hub. Here is the 201 response after I saved a primitive example payload with id "3" below:

{"test": "value"}

Now if I try to generate a JavaScript code snippet and use it in my own application to call the service directly, I receive a 500 error. Here is the code I use:

writeData: function () {
			var data = JSON.stringify({
				"test": "value"
			});
			var xhr = new XMLHttpRequest();
			xhr.withCredentials = false;
			xhr.open("POST", "https://blockchain-service.cfapps.us10.hana.ondemand.com/blockchain/proofOfState/api/v1/states/4");
			xhr.setRequestHeader("Content-Type", "application/json");
			xhr.setRequestHeader("Accept", "application/json");
			xhr.setRequestHeader("Access-Control-Allow-Credentials", "true");
			xhr.setRequestHeader("Access-Control-Allow-Origin", "https://<myRouter>-approuter.cfapps.us10.hana.ondemand.com");
			xhr.setRequestHeader("Access-Control-Allow-Headers", "access-control-allow-origin,authorization,content-type");
            xhr.setRequestHeader("Access-Control-Allow-Methods", "GET,HEAD,PUT,PATCH,POST,DELETE");
			xhr.setRequestHeader("Authorization", "Bearer <myToken>");
			
			xhr.onload = function () {
				if (xhr.status === 200) {
					alert("Sucessfully called the API!");
				} else {
					alert("Calling the API failed");
				}
			};
			xhr.send(data);
		}
Here is the 500 response from the service:

{"error":{"code":500,"message":"{\"statusCode\":500} - Please see our documentation at https://help.sap.com/viewer/p/BLOCKCHAIN_APPLICATION_ENABLEMENT/"}}


Mind you, it's not a 403 or a CORS error. I already resolved those. The call does reach the service and I can see it in the dashboard as below:

I don't understand why is it 500? The worst thing that the service doesn't provide explanation and the error is not traceable anywhere. I suspect my payload is not correct, but the documentation doesn't give any examples of a proper payload for a post operation.

So I'd be really grateful if you could suggest anything or give an example of how the service should be called.

Thank you!

------------------------------------------------------

I already looked at the following examples, but couldn't find an answer:
https://developers.sap.com/tutorials/blockchain-application-enablement-proofstate.html
https://help.sap.com/viewer/71a0bb282b2144c6b27fefc772394bff/BLOCKCHAIN/en-US/58cfd045142c4696baced29cfcc3dcc8.html
https://github.wdf.sap.corp/blockchain/timestamp/blob/master/index.js

Attachments