Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ritesh 3 posts 73 karma points
    Apr 15, 2022 @ 13:45
    Ritesh
    0

    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

  • Mehmet Avcı 55 posts 240 karma points
    Apr 18, 2022 @ 10:36
    Mehmet Avcı
    0

    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

  • Ritesh 3 posts 73 karma points
    Jul 28, 2022 @ 11:39
    Ritesh
    0

    Thanks.

    It looks like issue with visual studio compiler. After restarting my machine I httpclient was working fine.

    thanks for your help.

Please Sign in or register to post replies

Write your reply to:

Draft