Closed yieniggu closed 5 years ago
UPDATE:
Changed to swagger library (still in Node.js). Thinking of a more compatible way to interact with the resource. This is the new portion of code:
var qs = require('qs');
const axios = require('axios');
const Swagger = require("swagger-client");
const AUTHORITY = 'https://login.microsoftonline.com/*';
const WORKBENCH_API_URL = 'https://scompblockchain1-6jii2u-api.azurewebsites.net';
const RESOURCE = '*';
const CLIENT_APP_Id = '*';
const CLIENT_SECRET = '*';
// Getting token from AAD
const acquireTokenWithClientCredentials = async(resource, clientId, clientSecret, authority) => {
const requestBody = {
resource: resource,
client_id: clientId,
client_secret: clientSecret,
grant_type: 'client_credentials'
};
console.log(acquireTokenWithClientCredentials);
const response = await axios({
method: 'POST',
url: `${authority}/oauth2/token`,
data: qs.stringify(requestBody),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
return response.data;
}
main = async() => {
try {
const token = await acquireTokenWithClientCredentials(RESOURCE, CLIENT_APP_Id, CLIENT_SECRET, AUTHORITY);
const request = {
url: `${WORKBENCH_API_URL}/api/v2/contracts?workflowId=1&contractCodeId=1&connectionId=1`,
method: "POST",
headers: { 'Content-Type': 'application/json;charset=utf-8;odata=verbose', 'Authorization': `Bearer ${token.access_token}`},
body: {
workflowActionInput: {
workflowFunctionID: 1,
workflowActionParameters: [{
name: "description",
value: "Quiero verder un auto",
workflowFunctionParameterId: 2
},
{
name: "price",
value: "2500000",
workflowFunctionParameterId: 3
}
]
}
}
}
let res = await Swagger.http(request);
/*const request = await axios({
method: "POST",
url: `${WORKBENCH_API_URL}/api/v2/contracts?workflowId=1&contractCodeId=1&connectionId=1`,
headers: {'Authorization': `Bearer ${token.access_token}` },
data: {
workflowActionInput: {
"workflowFunctionID": 1,
"workflowActionParameters": [
{
"name": "description",
"value": "Quiero verder un auto",
"workflowFunctionParameterId": 2
},
{
"name": "price",
"value": "2500000",
workflowFunctionParameterId: 3
}
]
}
}
});*/
//console.log("POST COMPLETADO (?: : ", res);
}
catch (err) {
console.error(err);
}
}
main();
And this is the actual error log:
{ Error: Bad Request at Function.<anonymous> (/home/ubuntu/workspace/Example/blockchain/blockchain-workbench/auth-samples/nodejs/node_modules/swagger-client/dist/index.js:1:8679) at tryCatch (/home/ubuntu/workspace/Example/blockchain/blockchain-workbench/auth-samples/nodejs/node_modules/regenerator-runtime/runtime.js:62:40) at Generator.invoke [as _invoke] (/home/ubuntu/workspace/Example/blockchain/blockchain-workbench/auth-samples/nodejs/node_modules/regenerator-runtime/runtime.js:296:22) at Generator.prototype.(anonymous function) [as next] (/home/ubuntu/workspace/Example/blockchain/blockchain-workbench/auth-samples/nodejs/node_modules/regenerator-runtime/runtime.js:114:21) at step (/home/ubuntu/workspace/Example/blockchain/blockchain-workbench/auth-samples/nodejs/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30) at /home/ubuntu/workspace/Example/blockchain/blockchain-workbench/auth-samples/nodejs/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13 at processTicksAndRejections (internal/process/next_tick.js:81:5) status: 400, statusCode: 400, response: { ok: false, url: 'https://scompblockchain1-6jii2u-api.azurewebsites.net/api/v2/contracts?workflowId=1&contractCodeId=1&connectionId=1', status: 400, statusText: 'Bad Request', headers: { 'transfer-encoding': 'chunked', 'content-type': 'application/json; charset=utf-8', server: 'Kestrel', 'request-context': 'appId=cid-v1:db0d0b41-4c65-4302-8151-77d69bdb0b7b', 'x-correlation-id': '3bd77780-6a2d-4917-ab93-388bd5a9a262', 'set-cookie': 'ARRAffinity=57e591747cde1209152d99cdbdb64ff3aaf6a1963b12c10e97bbe6fa5a4a72d6;Path=/;HttpOnly;Domain=scompblockchain1-6jii2u-api.azurewebsites.net', date: 'Fri, 15 Feb 2019 13:37:05 GMT', connection: 'close' }, text: '"Must provide a valid workflow action input"', data: '"Must provide a valid workflow action input"', body: 'Must provide a valid workflow action input', obj: 'Must provide a valid workflow action input' } }
Thanks for the detail. I'm not sure what exactly is going on, but I would double check the input that you're putting in based on your config/smart contract that you uploaded. The error messages near the bottom seem to indicate that your workflow action input may not match properly.
@brendalee thanks for your answer, i think it's just a schema or library error used in my Node.js backend. I hope you can help me solve this, since api is the final step of my poc.
You can found here that using postman (after imported the collection as pointed here works perfectly, but from my backend stills outputs that must provide a valid workflow action input.
ServicePrincipal Token don't work fine. With administrator bearer token, work fine. Why? @brendalee administrator bearer token is copy and past from Web Portal of workbenck. @yieniggu any news of this bug?
If you're using a service principal for system to system integrations, we recommend use the messaging API, which will solve this issue. Let us know if you run into this problem again!
Hi, @yieniggu how did you fix the issue? I am facing a the same issue on postman with the API ti create a contract?
I found the same issue here as wel, any updates? https://social.msdn.microsoft.com/Forums/sqlserver/ja-JP/f7b04e01-bb7b-42ee-a1d7-0c125c1f52f9/error-in-createcontract-azure-blockchain-rest-api?forum=azureblockchain
Hi, @yieniggu how did you fix the issue? I am facing a the same issue on postman with the API ti create a contract?
I have the same issue when post a new contract via postman by impersonating a user.
when the post request is finished, there are no contract properties and ledgerIdentifier for this newly-created contract.
Moreover, there is no available actions for this contract.
What could possibly go wrong here? Or is this not a supported functionality right now?
Below is the data I get for the newly created contract
{ "id": 12, "provisioningStatus": 0, "timestamp": "2019-08-15T18:41:49.5566667", "connectionID": 1, "ledgerIdentifier": null, "deployedByUserId": 1, "workflowId": 2, "requestId": "7140c8cd-8174-46af-8c1e-bb0717e02073", "contractCodeId": 2, "contractProperties": [], "transactions": [], "contractActions": [ { "id": 30, "userId": 1, "provisioningStatus": 0, "timestamp": "2019-08-15T18:41:49.5566667", "parameters": [ { "name": "description", "value": "from postman", "workflowFunctionParameterId": 9 }, { "name": "transferability", "value": "true", "workflowFunctionParameterId": 10 }, { "name": "expired time", "value": "1569011400", "workflowFunctionParameterId": 11 } ], "workflowFunctionId": 7, "transactionId": null, "workflowStateId": null, "requestId": "7140c8cd-8174-46af-8c1e-bb0717e02073", "eventId": null } ] }
Make sure you are all using the correct parameter names in your JSON POST request. I was stuck for days but detailed information from this function helped me:
https://docs.microsoft.com/en-us/rest/api/azure-blockchain-workbench/applications/workflowget
This issue is for a: (mark with an
x
)Minimal steps to reproduce
First I created the service principal, as the docs request, for getting the bearer token and access the api resources.
Then, perform a GET request to /api/v1/applications/workflows/ and get the following results:
Any log messages given by the failure
Finally, the log of the response shows:
Additionaly, this is one of the logs of the application insights service in my blockchain workbench resources group, after it receives a POST request:
Apologize if the content of this is too long, just wanted to be sure to give every detail. Is this a problem with the api, the code syntax or an azure problem?
PD: All permisions on azure have been granted as the docs point.