
In my last article I showed how to work with a collection in a process. In this article I’ll be doing something similar but this time the collection will be coming from a web service. I’ll be using the web service element in the process so I’ll be covering how to use that. I’ll also cover how to set up the web service to use it from Creatio.
For the scenario of this article I’ll be using Mailchimp. My process will read all of the members or contacts in a list from Mailchimp and add them as contacts in Creatio. I’ll be using the Mailchimp API to read all of the contacts from Mailchimp. The API will give them back to me as a collection of records and then I will pass that collection to a sub process just as I did in my last article.
To use an API in a process in Creatio you must set it up as a web service first. To do that you must go to web services integration setup and add in your url of the API you’re going to be working with.
The picture below is what your page should look like once you enter your API. Next thing you’ll want to do is click on the web service method that got created when you pasted in the url.
Once you click on your method go to response parameters and on the top of the page there’ll be a quick setup button you’ll want to click on that and go on “Example in JSON” but make sure you choose the one under “From Response Example”.
When you do this, it will open a window where you can paste in a sample of the JSON returned by the web service. What I did was use postman to call the API and then copied the JSON that I got back to paste in this window. Creatio uses that to create all of the parameters of what you get back from the API. Once it does this it’ll look like this image below.
Now we will set up the process. The first thing you’ll want to do is call your web service and then pass the collection from the web service to a sub process. The process will look like this.
To set up the web service component you’ll just add your web service you just created where it asks you which service you want to call.
This is what your sub process should look like, for my scenario, the API is returning a First name, Last name, and Email address. I want to pass all three of these values to the sub-process. To do this you have to make sure to create 3 text parameters for the process, one for the email, first name and last name (we will merge the first and last name together later).
All your sub process is going to have in it is one add data, which will use the process parameters passed in to create a contact.
In the add data your going to be adding to contact, we’ll be setting the email and full name values with the parameters we passed to the sub process earlier. With the full name I just did a formula and added the first and last name together.
That’s really all there is to it, the key is to set up the web service so you can add it to your process. After that working with the collection returned by the web service is just like working with a collection from a read data task like in my last article.
Hello Tate.
Nice work!
A simple question. Is there a way to Count the record collection that return the webservice?
Thank you for your help.
I’m not sure exactly, but it might work to do this in a script task (the web services element itself does not provide a count property). Something like this:
var list = Get>(“WebServiceTask1.ResultCompositeObjectList”);
var count = list.Count;
// now could set count back in a process param if wanted
Set(“MyCountParam”, count);
Note, in the above, you’d need to change the “WebServiceTask1” to whatever your web service element’s name is (click the three-dots button at top right and select advanced to get the name). Again, I am not 100% sure if the above works, but getting it in a script task would be the only way to get at that value.
Ryan