11 Replies Latest reply on Sep 9, 2020 3:53 PM by Clark Bohs

    Web API:  Unable to POST data from body

    Clark Bohs
      Share This:

      Hello,

       

      I'm having difficulty POSTing my data from the body section in my document.

       

      Here is the error I get when I run my Process:  [ERROR (5004): Web API execution error:; Status : 400, Reason : Bad Request, Response : {"errorMessages":["No content to map to Object due to end of input"]

       

      Here is my document.  It's in the Documents tab and is named JiraCloudPostCommentDoc.  Note it's in Atlassian Document Format because Atlassian requires that:

       

      {

        "body": {

          "type": "doc",

          "version": 1,

          "content": [

            {

              "type": "paragraph",

              "content": [

                {

                  "text": "Another Test Comment",

                  "type": "text"

                }

              ]

            }

          ]

        }

      }

       

      Here is the Web Request in my Process:

      Web_Request.PNG

       

       

      Here is my Web API:

       

      Web_API.PNG

       

       

      Here is my working curl call:

       

      curl -D- -u clarkbohs@gmail.com:<code that works> -X POST  https://clarkbohs.atlassian.net/rest/api/3/issue/CLAR-3/comment -d "{\"body\": {\"type\": \"doc\",\"version\": 1,\"content\": [{\"type\": \"paragraph\",\"content\": [{\"text\": \"Another Test Comment\",\"type\": \"text\"}]}]}}" -H "Content-Type: application/json"

       

      Thanks!

       

      --Clark

        • 1. Re: Web API:  Unable to POST data from body
          Laurent Matheo

          How did you set the body? In your process I see "body" as document value but I do not see it created.

          • 2. Re: Web API:  Unable to POST data from body
            Clark Bohs

            Hi Laurent,

             

            Here is how the document value is configured.   It's a Web Request value.

             

            I think you've hit upon my central question.  Where\How do I create this data so I can input it in to the Process and then to the Web API?

             

            As of now all I have is the document in the Documents tab but that's just a schema (?) and I would need to programmatically update this value.

             

            Body_in_Process.PNG

             

             

            I'm trying to get the value from this document but that doesn't make sense to me because isn't this a schema?   This is where I'm not understanding how to pass the data to the Web API from the Process.

             

            Doc.PNG

            • 3. Re: Web API:  Unable to POST data from body
              Laurent Matheo

              You have a "Create Document" Activity for that.

               

              You should create a process variable type Object using your body document "JiraPostComment".

              Then use an Activity "Create Document" to initialize the Document variable with some values.

              You can use the Activity "Update Document" to update the Document later on.

               

              There is a small example here:

              Re: How to update a Document

               

              Btw it seems that the json has arrays in it. Usually in this case I create several documents, so instead of:

              {

                "body": {

                  "type": "doc",

                  "version": 1,

                  "content": [

                    {

                      "type": "paragraph",

                      "content": [

                        {

                          "text": "Another Test Comment",

                          "type": "text"

                        }

                      ]

                    }

                  ]

                }

              }

               

              I would have this "JiraBody":

              {

                "body": {

                  "type": "doc",

                  "version": 1,

                  "content": []

                }

              }

               

              And "JiraType":

                    {

                      "type": "paragraph",

                      "content": []

                    }

               

              And "JiraComment":

                        {

                          "text": "Another Test Comment",

                          "type": "text"

                        }

               

              The reason I do this usually is because it is easier to add multiple data into an array using the Activity "Add Array Element to Document".

               

              In the process I would have three Object variable type document, JiraBody, JiraType, JiraComment (named varJiraBody, varJiraType, varJiraComment).

              I would do three "Create Document" with some default values for each one of them, saving (using Output Map) each one in their respective variable (see thread above)..

               

              For JiraBody the values would be:

              • For type: "doc"
              • For version: 1
              • For content:"[]"

               

              For JiraType the values would be:

              • For type: "paragraph"
              • For content:"[]"

               

              For JiraComment the values would be:

              • For text: "Hello World "
              • For type:"text"

               

              Then I would need to add JiraComment into the JiraType.content and JiraType into JiraBody.body.content.

              So multiple "Add Array Element to Document".

               

              So for JiraComment into the JiraType.content it would be an "Add Array Element to Document".

              • The Document is the "target" document you want to update, so here it would be "JiraType".
              • Document instance is the variable that you want to modify, so here the variable varJiraType.
              • Node Name the document node you want to update, so here we want to add the content of varJiraComment into varJiraType.content. So the node name you want to update is "content" (from the JiraType, you will have a selection helper).
              • The value is the document instance you want to insert, so here varJiraComment.
              • The index does not matter, you can let it as is. It would only matter if you wanted to add it at a specific position. You can put 0 I guess if you wanted to.

               

              Then in Output Map don't forget to assign to varJiraComment the Activity Output so it saves your modification.

               

              So now in varJiraType you should have:

                    {

                      "type": "paragraph",

                      "content": [

                        {

                          "text": "Hello world ",

                          "type": "text"

                        }

                      ]

                    }

               

              So now we need to put this content into the varJiraBody.body.content which has now:

              {

                "body": {

                  "type": "doc",

                  "version": 1,

                  "content": []

                }

              }

               

              So there again another "Add Array Element to Document".

              • The Document is the "target" document you want to update, so here it would be "JiraBody".
              • Document instance is the variable that you want to modify, so here the variable varJiraBody.
              • Node Name the document node you want to update, so here we want to add the content of varJiraType into varJiraBody.body.content. So the node name you want to update is "content" (from the JiraBody, you will have a selection helper).
              • The value is the document instance you want to insert, so here varJiraType.
              • The index does not matter, you can let it as is. It would only matter if you wanted to add it at a specific position. You can put 0 I guess if you wanted to.

               

              Then in Output Map don't forget to assign to varJiraBody the Activity Output so it saves your modification.

               

              So now your varJiraBody should contain:

              {

                "body": {

                  "type": "doc",

                  "version": 1,

                  "content": [

                    {

                      "type": "paragraph",

                      "content": [

                        {

                          "text": "Hello world :)",

                          "type": "text"

                        }

                      ]

                    }

                  ]

                }

              }

               

              Then in your web request you can use this varJiraBody to pass it to Jira.

               

               

              In your web api definition, the document you should use for the body is still the JiraBody.

              1 of 1 people found this helpful
              • 4. Re: Web API:  Unable to POST data from body
                Clark Bohs

                Thanks Laurent!  Great detail.  Let me work through this and I'll let you know how it goes. 

                • 5. Re: Web API:  Unable to POST data from body
                  Clark Bohs

                  Hey Laurent, I wanted to clarify something...

                   

                  Are you saying that it absolutely will not work if I try to use the entire original document below as the input?

                   

                  Or are you saying that it will work but it's not the preferred method?

                   

                  p.s.  I'm happy to use your preferred method but if I'm having a more fundamental issue with creating and passing my document then I want to resolve that first.

                   

                  Thanks!

                   

                   

                  {

                    "body": {

                      "type": "doc",

                      "version": 1,

                      "content": [

                        {

                          "type": "paragraph",

                          "content": [

                            {

                              "text": "Another Test Comment",

                              "type": "text"

                            }

                          ]

                        }

                      ]

                    }

                  }

                  • 6. Re: Web API:  Unable to POST data from body
                    Laurent Matheo

                    Tbh I never tried. It should be possible yes, but you will still need to use the "Create Document" activity to create an instance of this document and pass this instance to the rest api.

                    I wonder if you can pass directly the text in the Web Request if you want to test.

                    1 of 1 people found this helpful
                    • 7. Re: Web API:  Unable to POST data from body
                      Clark Bohs

                      Yep I've now got my Create Document in my Process.

                       

                      If you don't mind I would like to try to get the "one doc" method to work.  I figure if curl can do it then Helix should be able to do it.

                       

                      Let me see how far I get and I'll reach out if/when I get stuck.

                       

                      Thank you so much for working with me on this!

                       

                      --Clark

                      • 9. Re: Web API:  Unable to POST data from body
                        Clark Bohs

                        Hey Laurent, I was able to configure my Process to create a Jira comment using only one Create Document activity.

                         

                         

                        First I'll run the Process.  It requires an IssueID and the text for the new Comment:

                         

                        Process_Inputs.PNG

                         

                         

                         

                        Here is the new Comment in Jira Cloud:

                        Comment_In_Jira.PNG

                         

                         

                        Here is the entire Process.  Note there is just one Create Document activity:

                        Process.PNG

                         

                        Here are my Process Variables.  Note that Output Body is Text, not an Object.  The Header in the Connection for application\json takes care of that:

                         

                        Process_Variables.PNG

                         

                         

                        Here is the real magic...in the Create Document activity I select the nodes that will contain values.  Helix will build the entire JSON document for you...it just needs to know what nodes will contain values then you will supply those values in the next step:

                         

                        Add_Remove_Nodes.PNG

                         

                         

                         

                         

                        The Next Step:

                        Also in the Create Document activity you provide the values to the nodes you selected above.  I filled in all the required values that will not change (body.type, body.version, etc.).  The Comment Text is a Process Variable and is gathered as a required input to the Process.  All of this together creates the Output Body variable:

                         

                        Create_Document.PNG

                         

                         

                        Here is the Output of the Create Document activity, taking note of the Output Body that was created in the Create Document activity.  It's now ready to be sent to the Web Request:

                         

                        Output.PNG

                         

                         

                        Here is the Web Request activity.  Note that issueid and Output Body are sent to the REST API to POST the new Jira Comment:

                         

                        Web_Request.PNG

                         

                        That's it!

                         

                        --Clark

                        • 10. Re: Web API:  Unable to POST data from body
                          Laurent Matheo

                          Nice! ^_^

                           

                          Ah yes the famous [0] nodes, that is why I do not use a Document when there are nested arrays, because you are tempted to check the "parent" node which should not be set...

                          • 11. Re: Web API:  Unable to POST data from body
                            Clark Bohs

                            Hey Laurent,

                             

                            Once I figured out how "Add/Remove Document Nodes" works it was smooth sailing.   I like the way Helix wants to create the doc for you as much as possible.

                             

                            It appears that the Helix project took a lot of time and thought to alleviate a pain-point, which is the creation/parsing of json docs.  If you know the nodes where your data reside then just select those nodes and Helix creates the doc for you.   Now you just need to supply the data.  I think this is super-slick.

                             

                            I'm now working with the "Call Activity" activity.  My Create Issue process creates the Issue and then calls the "Add Comment" process to add a comment to the new Issue using the newly-created issueid as the input (and I added a "Comment Text" input variable).

                             

                            It works great!

                             

                            I should probably start creating my Views but this Process stuff is a lot fun.

                             

                            Call_Activity.PNG

                             

                            Thanks for all of your great support and info.  You've really helped me come a long way 

                             

                            --Clark