Try our conversational search powered by Generative AI!

Mark Hall
Aug 15, 2018
  3149
(6 votes)

ServiceApi Customers and Organizations Extended

Recently I helped a couple of partners who needed to be able to update custom properties on customers and organizations using the service api.  I sent them some code and thought I would share here for anyone else who might need.  Hopefully soon this will be in the product as it is on the backlog.

Since there is seven files I created a sample project on my github where you can see the extensions  

https://github.com/lunchin/EPiServer.ServiceApi.Extended.Sample

To use the extensions, install the repo and refer to the API folder and specifically CustomerExtendedController.  This api controller exposes the new endpoints. Next weill use postman to demonstarte how to use the new endpoints.

  1. First we need to get the token for our request

       Image Token.png

       2. Next we will do a get on the contacts to make it easy to do an update the contact.  Make sure you add the authorization bearer token you received from the previous request

Image GetContacts.png

    3.  Finally lets update the contact with a PUT.  First I show the body payload and then the request in postman.

{
        "FirstName": "Order",
        "LastName": "Manager",
        "Email": "manager@unknowdomain.domain",
        "RegistrationSource": "john",
        "PrimaryKeyId": "3e6c1665-3d09-49f6-8c1a-fc91e7341dae",
        "Addresses": [],
        "MetaFields": [
            {
                "Name": "Created",
                "Type": "DateTime",
                "Values": [
                    "2018-06-06T11:28:28.2170000-07:00"
                ]
            },
            {
                "Name": "Modified",
                "Type": "DateTime",
                "Values": [
                    "2018-06-06T11:28:28.2170000-07:00"
                ]
            },
            {
                "Name": "CreatorId",
                "Type": "Guid",
                "Values": [
                    "d4af0b76-3ea8-4a3a-86ea-22d4b3ca2552"
                ]
            },
            {
                "Name": "ModifierId",
                "Type": "Guid",
                "Values": [
                    "9c28ec95-fdec-41e9-aa1e-8acfcc58c074"
                ]
            },
            {
                "Name": "FullName",
                "Type": "Text",
                "Values": [
                    "Order Test"
                ]
            },
            {
                "Name": "UserId",
                "Type": "Text",
                "Values": [
                    "String:manager"
                ]
            }
        ]
    }

Image PUT.png

Aug 15, 2018

Comments

K Khan
K Khan Aug 16, 2018 09:00 AM

Thanks for sharing

Please login to comment.
Latest blogs
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog