Use the API block for an easy way to import or update contacts with segment values. Yup, that's right. We already introduced you to our API, where we showed you how to let your contacts come through the API entry block. If you missed this, go ahead and find out more in the API entry block article.
Let's see now how to add and update segment values through the API block.
API segment mapping
The API segment mapping is the same as any other string value.
- Use our API to Copy/paste the JSON body.
- If the HTTP Status Code is 200, go back to the Flow.
- The Manage API entry mapping window should be open and simply map your segment field with the Loopify field. Your segments can be stings or array of strings, and it can be mapped one or the other way.
Here take a look at our JSON example:
Now, your API block should be successfully mapped! All that is left now is to set the campaign Live and Trigger the block.
Update and clear segment values through the API
Now, you can use the API to add contacts to segments or use a boolean value to clear the segment.
- To use this option you should first map the API block and set the Flow to an Active state in order to trigger the API block.
- When you are in the right endpoint to trigger the API block, you are able to add the parameters 'addToSegment' and 'clearSegment' in the API call that will only affect all contacts send in the API call.
- This method, when using the 'addToSegment' parameter will check if the segment already exists and add the contacts to the wanted segment. If the segment doesn't exist this will create a new segment and then add all the contacts to the new segment.
- You can also use the 'clearSegement: true' option, which will remove all other contacts from the chosen segment, and import the new contacts to the segment. This option will only have an effect if the 'addToSegment' is set.
Note: When using the 'clearSegment' option, the contacts will not be deleted but they will be removed from the specific segment that you specify.
Here is an example:
With this JSON example, we set the options so that our contacts will be added to the segment 'customers'. If this segment doesn't exist in Loopify, this method will add the segment group. And If this segment exists and we already have contacts in the contacts segment, the 'clearSegment' option will remove those contacts, and add the listed contacts to the segment.
- If you like your existing contacts to remain in the segment just set the clear segment option to "clearSegment": false
And voilà! 💁🏻 Now you are able to import and update your contacts with segment values. Now go forward and learn about the Loopify API methods.