Try our conversational search powered by Generative AI!

Mark Hall
Aug 15, 2018
  3170
(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
From Procrastination to Proficiency: Navigating Your Journey to Web Experimentation Certification

Hey there, Optimizely enthusiasts!   Join me in celebrating a milestone – I'm officially a certified web experimentation expert! It's an exhilarati...

Silvio Pacitto | May 17, 2024

GPT-4o Now Available for Optimizely via the AI-Assistant plugin!

I am excited to announce that GPT-4o is now available for Optimizely users through the Epicweb AI-Assistant integration. This means you can leverag...

Luc Gosso (MVP) | May 17, 2024 | Syndicated blog

The downside of being too fast

Today when I was tracking down some changes, I came across this commit comment Who wrote this? Me, almost 5 years ago. I did have a chuckle in my...

Quan Mai | May 17, 2024 | Syndicated blog

Optimizely Forms: Safeguarding Your Data

With the rise of cyber threats and privacy concerns, safeguarding sensitive information has become a top priority for businesses across all...

K Khan | May 16, 2024