cancel
Showing results for 
Search instead for 
Did you mean: 

jquery ajax post send json

davide_bramati
Advisor
Advisor
0 Kudos

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);
	}
});

Accepted Solutions (1)

Accepted Solutions (1)

alexander_gehres
Explorer
0 Kudos

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"]

Answers (3)

Answers (3)

alexander_gehres
Explorer
0 Kudos

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

ericci
Active Contributor
0 Kudos

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

Are you using the SAP Blockchain service?

davide_bramati
Advisor
Advisor
0 Kudos

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!

ericci
Active Contributor
0 Kudos

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

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.

davide_bramati
Advisor
Advisor
0 Kudos

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?

ericci
Active Contributor
0 Kudos

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.

davide_bramati
Advisor
Advisor

Ok, thank you for your support!

brian_keenan
Contributor
0 Kudos

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

davide_bramati
Advisor
Advisor
0 Kudos

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

But the apikey is correct.