Call external API on Publish event to create copy of data
Hi,
I am using Umbraco V8.18.3.
I have a requirement where I need to create a copy of content to other database (MongoDB).
For creating a copy of content, I am using existing external API endpoints.
Whenever any content is being published, I want to call external API and post data to it.
e.g. Whenever Blog is published, I want to call external API which will insert blog data using that API endpoint.
How can I call external API from ContentService_Published method?
I have tried to use HttpClient but Its not possible to use HttpClient in this method/class.
As a principle, I would suggest you to separate your tasks here. If you cannot which might be due to various reasons, (I don't really understand why you cannot use HttpClient) but you can give a shot to other similar classes or packages like RestSharp.
Imho, since this will be ongoing operation, you should add these to a queue and let these requests to be send separately than publish events. You will have a better control over fail scenarios without impacting actual publish operation.
Call external API on Publish event to create copy of data
Hi,
I am using Umbraco V8.18.3.
I have a requirement where I need to create a copy of content to other database (MongoDB). For creating a copy of content, I am using existing external API endpoints. Whenever any content is being published, I want to call external API and post data to it.
e.g. Whenever Blog is published, I want to call external API which will insert blog data using that API endpoint.
I am following article : https://our.umbraco.com/documentation/Fundamentals/Code/Subscribing-To-Events/ and subscribed to published event. I am able to get published content data to ContentService_Published method (please refer attached files). Now I want to call external API to post Blog data to API endpoint. e.g. https://www.myapi.com/Insertdata.
How can I call external API from ContentService_Published method? I have tried to use HttpClient but Its not possible to use HttpClient in this method/class.
Can anyone please help to achieve same?
Thanks, Ritesh
Hi Ritesh,
As a principle, I would suggest you to separate your tasks here. If you cannot which might be due to various reasons, (I don't really understand why you cannot use HttpClient) but you can give a shot to other similar classes or packages like RestSharp.
Imho, since this will be ongoing operation, you should add these to a queue and let these requests to be send separately than publish events. You will have a better control over fail scenarios without impacting actual publish operation.
Regards, Mehmet
Thanks.
It looks like issue with visual studio compiler. After restarting my machine I httpclient was working fine.
thanks for your help.
is working on a reply...