I am a developer with hyperledger composer. I try to use Calling an HTTP or REST API from Transaction Processor Functions with method POST and request body but I have error status code 500. I want to use method POST with request body to my server.
My code:
async function testStocks(transaction) {
const participant = getCurrentParticipant();
const json = '{"name:tester"}';//my request body
await request.post({ uri: 'http://www...', json });
// Update the current participant in the participant registry.
const participantRegistry = await getParticipantRegistry('org.example.Trader');
await participantRegistry.update(participant);
}
My error:
{
"error": {
"statusCode": 500,
"name": "Error",
"message": "Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: StatusCodeError: 400 - undefined",
"stack": "Error: Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: StatusCodeError: 400 - undefined\n at _initializeChannel.then.then.then.then.catch (/home/pc/.nvm/versions/node/v8.10.0/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:965:34)\n at <anonymous>"
}
}
participant
variable is undefined in await participantRegistry.update(participant);
.
You are missing code from the example @ https://hyperledger.github.io/composer/latest/integrating/call-out.
// Get the current participant, and update their stock and balance.
const participant = getCurrentParticipant();
// update participant here... <<--------------------
// Update the current participant in the participant registry.
const participantRegistry = await getParticipantRegistry('org.example.Trader');
await participantRegistry.update(participant);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments