Mark Hall
Aug 15, 2018
  3248
(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
Change texts in TinyMCE, inside Optimizely CMS 12

Not happy with some of the default texts in TinyMCE? Don't worry, simply update them.

Tomas Hensrud Gulla | Oct 16, 2024 | Syndicated blog

Headless with Content Delivery API

Hello Everyone, This blog will help anyone who wants to start or build an architecture of headless using content delivery api. When we shifted to...

PuneetGarg | Oct 15, 2024

Introducing Optimizely Graph Source .NET SDK

Overview Of Optimizely Graph Optimizely Graph is a cutting-edge, headless content management solution designed to integrate seamlessly with any...

Jake Minard | Oct 15, 2024

SEO redirects in .NET + Optimizely

Nice and easy way to add necessary SEO redirects

Damian Smutek | Oct 14, 2024 | Syndicated blog