Search code examples
rresthyperledgerhyperledger-composerhttr

How to give empty value for argument in POST request for hyperledger composer rest server


I am trying to make a post request via R using the httr package to composer rest server. I have written a code and then created the composer rest server from it. These are my details

Request URL : http://localhost:3000/api/nl.amis.registry.fruits Body: { "$class": "nl.amis.registry.fruits", "Id": "9", "name": "orange", "description": "string", "count": "" } First, I have tried with the composer rest server. For my purpose, I needed the count to be blank and the value will be appended by another API call. I was able to make the transaction successfully with the count: "". This I was able to check in the test section of the composer playground. The remaining code works fine which appends the count variable later on.

Now I am writing an R code to make a similar transaction through POST request. Here I am facing an error that "count cannot be blank" and returns with error 422 Unprocessable entity. The content type I was used was application/json. While using the "count":{} , the post request process fine and i am getting "count":[object Object] in the response. But the later on code which does the appending will do something like count:"[object Object],1" wherein I am expecting "count":"1". Everything works fine while using the test in composer playground but while trying to access externally via rest API is creating the problem. Please help.


Solution

  • you can use an Optional keyword to declare a count in an asset of the model file. using Optional keyword you can post an empty value of count.

    for example:

      asset fruits identified by Id {
        o String Id
        o String name
        o String description
        o String count optional
      }