Try our conversational search powered by Generative AI!

Mark Hall
Aug 15, 2018
  3191
(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
Optimizely Search and Navigation - Part 2 - Filter Tips

Introduction Continuing from Part 1 – Search Tips , today I will share the next part – filter tips. The platform versions used for this article are...

Binh Nguyen Thi | Jul 1, 2024

Integrating HubSpot CRM without the MA Connector

Have HubSpot CRM? Want to push user data into it from Optimizely? Don’t have any personalisation requirements with that data? Don’t want to pay $80...

Matt Pallatt | Jun 27, 2024

Keeping the website secure by updating external packages

Did you see the latest warning from Optimizely to update this package with a critical security warning? https://world.optimizely.com/documentation/...

Daniel Ovaska | Jun 27, 2024

Optimizely CMS image anonymization now available for Linux!

The famous image anonymization add-on for Optimizely CMS, with at least 5 downloads, is now finally available for use on Linux. Supports simultaneo...

Tomas Hensrud Gulla | Jun 25, 2024 | Syndicated blog

Remove a segment from the URL in CMS 12

Problem : I have created thousands of pages dynamically using schedule jobs with different templates (e.g. one column, two columns, etc..) and stor...

Sanjay Kumar | Jun 21, 2024

Copying property values part 2

After publishing my last article about copying property values to other language versions, I received constructive feedback on how could I change t...

Grzegorz Wiecheć | Jun 18, 2024 | Syndicated blog