cancel
Showing results for 
Search instead for 
Did you mean: 

Blue Prism Web API with collection.

LasseSørensen
Level 3

Hi. Im having big problems getting a Web API to take data from af collection and sending a message.

My Template is like this.

{ 
  "MessageBody": {
    "LegalEntityId": "[LegalEntityID]",
    "SourceSystem": "[SourceSystem]",
    "JournalLines": [
      {
        "SourceSystemId": "[JournalLines_new.SourceSystemId]",
        "Date": "[JournalLines_new.Date]",
        "ProjectId": "[JournalLines_new.ProjectId]",
        "EmplId": "[JournalLines_new.EmplId]",
        "ICWarehouse": "[JournalLines_new.ICWarehouse]",
        "ICLocation": "[JournalLines_new.ICLocation]",
        "Qty": [JournalLines_new.Qty],
        "ItemId": "[JournalLines_new.ItemId]",
        "WorkorderId": "[JournalLines_new.WorkorderId]"
      }
    ]
  }
}

In the object i have two dataitems called "LegalEntityID", and "SourceSystem", and a Collection called "JournalLines_new"

It takes the LegalEntityID, and SourceSystem correctly, but the collection beings passed to the object that handles the API call is being ignored.

I have tried the Utility - JSON to convert the collection to a JSON string and skipping the internal collection completely, but the message being sent is always blank apart from LegalEntityID and Source system.

This is a grab of the RequestData output.

Content-Length: 362
Expect: 100-continue
Connection: Keep-Alive
{ 
  "MessageBody": {
    "LegalEntityId": "Test",
    "SourceSystem": "RPA",
    "JournalLines": [
      {
        "SourceSystemId": "",
        "Date": "",
        "ProjectId": "",
        "EmplId": "",
        "ICWarehouse": "",
        "ICLocation": "",
        "Qty": ,
        "ItemId": "",
        "WorkorderId": ""
      }
    ]
  }
}
1 BEST ANSWER

Helpful Answers

LasseSørensen
Level 3

Hi Everybody.

I think i have fixed it 😄

Now at least the RequestData output fills in my data.

The fix was to send the Collection to the Object, use a MultiCalc step, to split it into single dataitems, and then pass those to the call.
35272.png35273.png35274.png

Right now i am waiting for someone on the other end to veryfy that something has been recieved.

View answer in original post

10 REPLIES 10

ewilson
Staff
Staff
Hi @LasseSørensen,

If all else fails, you can switch from a Template to Custom Code for the body and simply write some C# or VB.NET to build the JSON body you're looking for.

Cheers,
Eric​

Hi @LasseSørensen

I believe the collection name should exactly match the name of the collection from the template. In your case you have the collection name as JournalLines_new but it should be set as JournalLines. I dont think the collection field names need to be specified in the template as long as the collection you have defined as an input has the same name fields.​

LasseSørensen
Level 3

Hi @Michael ONeil

Thanks for the ​suggestion.

So it should look like this instead if i understand you correctly?

{ 
  "MessageBody": {
    "LegalEntityId": "[LegalEntityID]",
    "SourceSystem": "[SourceSystem]",
    "JournalLines": "[JournalLines]"
  }
}


Unfortunatly when i do that i get "ERROR: Internal : Unexpected error Error during Web API HTTP Request."

Hi

Actually I think it should look more like the below. Your parameters would be set as LegalEntityID, SourceSystem and JournalLines. This is how I've built an api template Im currently working on but mine is using SOAP XML but I'm assuming the same should work for yours. 

{
  "MessageBody": {
    "LegalEntityId": "[LegalEntityId]",
    "SourceSystem": "[SourceSystem]",
    "JournalLines":
      {
        "SourceSystemId": "",
        "Date": "",
        "ProjectId": "",
        "EmplId": "",
        "ICWarehouse": "",
        "ICLocation": "",
        "Qty": ,
        "ItemId": "",
        "WorkorderId": ""
     }
  }
}

LasseSørensen
Level 3

Hi again @Michael ONeil

Thanks for the suggestion,

When i try that, i get this as the RequestData

Content-Length: 351
Expect: 100-continue
Connection: Keep-Alive
{
  "MessageBody": {
    "LegalEntityId": "Test",
    "SourceSystem": "RPA",
    "JournalLines":
      {
        "SourceSystemId": "",
        "Date": "",
        "ProjectId": "",
        "EmplId": "",
        "ICWarehouse": "",
        "ICLocation": "",
        "Qty": ,
        "ItemId": "",
        "WorkorderId": ""
     }
  }
}


​So unfortunatly still not success, even though i have made sure the names in the collection are identical to the ones in the template.

Can you add some screenshots of the web service set up and of the action?

ewilson
Staff
Staff
@LasseSørensen,

Here's an example of what I was referring to about using a Custom Code option instead of Template.

35267.png

In this example, I'm building the request body by using a .NET StringBuilder object. This is C#, but you could do the same thing with VB.NET with a few minor format changes. You will need to include a reference to the System.Text namespace under the Common Code -> Code Options section as pictured below.

35268.png

Here's the code shown above:

StringBuilder payload = new StringBuilder();

payload.Append("{");
payload.Append("\"MessageBody\": {");
payload.Append("\"LegalEntityId\": \"" + LegalEntityID + "\",");
payload.Append("\"SourceSystem\": \"" + SourceSystem + "\",");
payload.Append("\"JournalLines\": [");

foreach (DataRow journalLine in JournalLines.Rows)
{
	payload.Append("{");
	payload.Append("\"SourceSystemId\": \"" + journalLine["SourceSystemId"].ToString() + "\",");
	payload.Append("\"Date\": \"" + journalLine["Date"].ToString() + "\",");
	payload.Append("\"ProjectId\": \"" + journalLine["ProjectId"].ToString() + "\",");
	payload.Append("\"EmplId\": \"" + journalLine["EmplId"].ToString() + "\",");
	payload.Append("\"ICWarehouse\": \"" + journalLine["ICWarehouse"].ToString() + "\",");
	payload.Append("\"ICLocation\": \"" + journalLine["ICLocation"].ToString() + "\",");
	payload.Append("\"Qty\": " + journalLine["Qty"].ToString() + ",");
	payload.Append("\"ItemId\": \"" + journalLine["ItemId"].ToString() + "\",");
	payload.Append("\"WorkorderId\": \"" + journalLine["WorkorderId"].ToString() + "\",");
	payload.Append("},");
}

payload.Append("]");
payload.Append("}");
payload.Append("}");

Request_Content = payload.ToString();​

Another option, code based, would be to create an actual object definition in the global code for the MessageBody object. Then you could just use Newtonsoft and object serialization to automatically generate the JSON body based on it's properties.

Cheers,
Eric

Hi, @LasseSørensen,

when I was playing with REST API call as an early adopter I got following structure which worked. I hope it helps you. I checked the documentation here https://bpdocs.blueprism.com/bp-7-1/en-us/api-spec-7-1-0.html#tag/Work-Queues/paths/~1api~1v7~1workqueues~1{workQueueId}~1items~1batch/post and it seems still valid. I think that the whole message needs to be enclosed in square brackets.

Regards

Zdenek

[
         {
                 "data": {
                          "rows": [
                                   {
                                   "ItemKey": {
                                            "valueType": "text",
                                            "value": "001"
                                            } ,
                                   "name": {
                                            "valueType": "text",
                                            "value": "zdenek"
                                            },
                                   "surname": {
                                            "valueType": "text",
                                            "value": "kabatek"
                                            }
                                   }
                          ]
                          },
                 "deferredDate": "2021-04-11T19:00:00Z",
                 "priority": 0,
                 "tags": [
                          "This is testing REST API"
                          ],
                 "status": "Ready for processing"
         }
]

LasseSørensen
Level 3
Hi @Michael ONeil

35269.png35270.png35271.png