Sitefinity. Добавление значения связанных данных к элементу с помощью веб-сервисов из контроллера - PullRequest
0 голосов
/ 24 января 2020

Итак, у меня есть предмет, который может иметь связанные офисы. Я пытаюсь опубликовать руководства соответствующих офисов в веб-сервисе, но продолжаю получать 400 ошибок.

apiUrl = "http://******/api/*******/firms(" + firmId + ")/RelatedOffices/$ref";
request = new HttpRequestMessage(HttpMethod.Post, apiUrl)
{
    Content = new StringContent("{ \"@odata.id\" : \"http://******/api/*******(" + office + ")\"}", Encoding.UTF8,  "application/json")
};
response = await httpclient.SendAsync(request).ConfigureAwait(false);

переменная "office" - это guid, как и "firmId". Если бы кто-то мог пролить свет на то, что не так, это было бы очень признательно. Я использовал эту документацию sitefinity, чтобы попытаться заставить ее работать без удачи:

Relate an item using a related data field
Request type: POST

Format: {{baseurl}}/api/default/{{entity}}({{item_to_add_related_content_to_id}})/{{related_data_field_name}}/$ref

To create an item relation, you need to make a POST request to the desired content item, which has a related data field you want to populate. In the URL you also need to specify the related data field name, using the /{{related_data_field_name}}/$ref endpoint. In the request body you must specify the web service URL to the item you want to relate in JSON format using the @odata.idparameter, similar to: { "@odata.id":"{{baseurl}}/api/default/{{entity}}({{item_to_relate_id}})" }.

For example, if you have a “RelatedImages” related media field for your news items, and you want to relate an image to one of your news items you must make a POST request to example.com/api/default/newsitems(d004c824-e22e-4037-9550-489f373b28c1)/RelatedImages/$ref . In the body of the request specify {"@odata.id" : "example.com/api/default/images(45cf53e4-1f0a-4f3f-9bd3-c880b5dbeb7c)"}
...