Skip to Content
0

jquery ajax post send json

Sep 03 at 08:00 AM

80

avatar image

Hi everybody,

I'm trying to develop an application for a blockchain scenario (digital asset transfer) but unfortunately when I launch the app I get an error (403 forbidden).

If I execute the json-rpc call with Postman, everything works fine but if I use the following code in the controller.js in Web IDE it doesn't work.

I have already set up the destination in SCP and in the neo-app.json.

Could you please help me to solve this issue?

jQuery.ajax({
	type: "POST",
	url: "/blockchainasset/*******************************/rpc",
	beforeSend: function (request) {
	request.setRequestHeader("apikey", "************************");
	},
	data: JSON.stringify({
	     "method": "getaddresses"
	}),
	dataType: "json",
	contentType: "application/json",
	success: function (data, textStatus, jQxhr) {
		console.log(data);
	},
	error: function (jqXhr, textStatus, errorThrown) {
		console.log(errorThrown);
	}
});
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Brian Keenan
Sep 03 at 10:07 AM
0

i would say this is related to the destination, what is the error you are seeing in the network tab? check the url is formed correctly

Show 1 Share
10 |10000 characters needed characters left characters exceeded

The error is {message: "header field APIKEY or token not provided"}.

But the apikey is correct.

0
Emanuele Ricci Sep 03 at 12:08 PM
0

I think that the main problem is the authentication in your destination.

Are you using the SAP Blockchain service?

Show 5 Share
10 |10000 characters needed characters left characters exceeded

Ciao Emanuele,

yes I'm using the SAP Blockchain service (multichain).

It seems that the destination does not accept the apikey.

The 403 error when I use the application is {message: "header field APIKEY or token not provided"}.

Thanks!

0

Well, the obvious question is: are you passing the APIKEY inside the request's header? :D

I don't remember the reason but we needed to add to the layer an external expressjs middleware to handle the REST request to the Blockchain API instead of passing directly through XSJS (we didn't have XSA but only XSC).

Another important thing: we din't use the multichain service.

0

Yes, I'm passing the APIKEY inside the request's header.

Thanks for your suggestion; since I'm not a developer expert, where do I have to add the expressjs middleware?

0

ExpressJS is just a nodejs framework that allows you to build a nodejs backend. You can deploy it wherever you want. But this was my solution. I would suggest you to contact someone from SAP to choose the best option that fit your needs. You also should be able to use SAP API huh to connect to your Blockchain service.

0

Ok, thank you for your support!

1
Alexander Gehres
Sep 12 at 05:59 PM
0

Hi Davide.

This most likely seems to be a CORS problem.

You won't be able to call MultiChain RPC Endpoint using only a frontend application because of security concerns.

Greetings,

Alex

Share
10 |10000 characters needed characters left characters exceeded
Alexander Gehres
Sep 14 at 01:22 PM
0

Hi Davide,

there seems to be a solution for this problem:

Please try to whitelist the APIKEY header field by adding the following entry to the neo-app.json:

"headerWhiteList": ["APIKEY"]

Share
10 |10000 characters needed characters left characters exceeded