1

I am using sitecore rest api, I am able to create item, also populate Content item values (for Field type Single-line) with PoSt method. Content field values are being in passed in body of rest client post request. ( ex: body{“fieldname”:”value”})

Similarly, with create item call, I am trying to populate the value for multilist field value. tried two different ways to do that: first - same as described above (pass the value as string) and second by passing itemId( the one to shown as selected value) as string value.

First approach ( passing the value): result is: the item is created and in multilist field, the selected values , shows the value passed in api appears, however it also shows error and in left side of multilist, all the values present. same result. For second approach, but shows different error in selected value side of the box

Maybe I need to make two calls to achieve this, one call to create item and one to update item.

Trying to find if I can do both in one call and populate multilist field value as well properly.

[![Error Screenshot updated][1]][1]

Updated post with - Error screenshot

Updated post for Media items creation - sorry for combining two questions

Query 2)

Sitecore REST API media item- Resource was not found

Updated . Posted the media item creation in new thread, so that I can close initially query (Multilist) as resolved .

2 Answers 2

1

To set the multiple selected value for multilist field you need to pass GUIDs separated by a |.

For example Service is multilist field here and selected values are guid of items.

{ 
    "ItemName": "MyItem5", 
    "TemplateID": "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}",
    "Title": "Sitecore ItemService",
    "Text": "API called",
    "Service": "{D3BCD9DF-A90E-454F-849C-8528FB3948E1}|{F26695CB-180D-4360-AC72-C285A11545C0}"
}

You can also try these steps in Postman to create a new item using ItemService API. Refer The RESTful API for the ItemService

  1. Authentication - first step into establishing a connection is to Authenticate the REST API.
  2. Setup a post request for Create Item API. In this case create item under home item. URL = https://<your server>/sitecore/api/ssc/item/sitecore%2Fcontent%2Fhome?database=master&language=en enter image description here

Check the response status 201 Created.

  1. Now you can validate your newly created item.

enter image description here

Updated

As per your attached screenshot, it looks like OTWC item id not properly mapped to the HandbookType fild. If you pass valid ID it will be mapped to the selected value. You can also check the Raw value from view menu. value should be an item id. i.e {4167291E-80EC-47D1-850E-B01B9322575E}.

Hope it helps!

8
  • Thanks @Sumit. In my case Template is already present in Sitecore CM with Multilist Field and the Template multilist Field has datasource path updated to a content Folder . Programmatically I am creating content with the existing template ID and passing one of the sitecore item's ID (which is present in the content items folder , which was updated as data source to the template multilist Field ). I will try to pass two values with Pipe and see how it works.
    – Akshay D
    Commented May 2, 2023 at 5:40
  • Thanks @sumit-helaiya on updated comment. if you any input or example for creating media items using REST API, could you please share ? Thanks
    – Akshay D
    Commented May 2, 2023 at 18:13
  • 1
    Does this resolved your 1st question? Commented May 2, 2023 at 18:16
  • 1
    Yes @sumit-helaiya. its working. it turns out , I was just missing the flower brackets around the item ID, that is passed as selected value . Thank you!
    – Akshay D
    Commented May 2, 2023 at 18:49
  • created different thread for media item question. @sumit-helaiya. sitecore.stackexchange.com/questions/34833/…
    – Akshay D
    Commented May 2, 2023 at 19:06
1

I am not sure what error you are getting on the selected value side of the box. But if you see the raw value (valued stored in the database) of the Multilist field, you will find a list of Sitecore Item Ids with pipe(|) separated strings like below.

enter image description here

So I tested this by a Postman request and was able to create an Item by passing the Multilist Data in a pipe separate string like below.

{ 
    "ItemName": "API Item 3", 
    "TemplateID": "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}",
    "Title": "Sitecore ItemService",
    "MultilistData": "{C31F1D0A-E16A-4500-B2B9-00B3F090722C}|{64F4D5C1-44BD-42B2-8E7C-81BE8D6668A7}"
}

And the item I created with the selected value I have given is this.

enter image description here

It may happen if you are providing the wrong item IDs that don't exist in your Sitecore database. If so, the selected value side will look like this.

enter image description here

So make sure you are passing the correct data to create an item via API call.

Finally, if you are getting some other error, please mention this in your question.

Hope this helps.

1
  • Thanks @Sumit. In my case Template is already present in Sitecore CM with Multilist Field and in Template - the multilist Field has datasource path updated to a content Folder . Programmatically I am just creating content with the template already present in Sitecore -CM with Multilist. While creating the items, I am passing one of the sitecore item's ID (which is present in the content items folder , which was updated as data source to the template multilist Field ). I will try to pass two values with Pipe and see how it works.
    – Akshay D
    Commented May 2, 2023 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.