Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Manually add attendee to event in external application in C#

(0) ShareShare
ReportReport
Posted on by 35

When we tried using the C# to call Event API.

We have tried using HttpWebRequest, WebClient, and HttpClient, all get 400 Bad Request.

  • FlowerPi Profile Picture
    FlowerPi 35 on at
    RE: Manually add attendee to event in external application in C#

    Hi Clofly,

    Thanks a lot! It works perfectly! Thank you so much!

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Manually add attendee to event in external application in C#

    Hi FlowerPi,

    I have split your question from the previous thread, a new thread would help people who have same question about how to call Event API in C#.

    We can solve it by adding http://localhost:8080 as Origin value in request headers. (If Origin field of your web application is http://localhost:8080.)

    4353.JPG

    static void Main(string[] args)
    {
        String endPoint = "https://123456.svc.dynamics.com/EvtMgmt/api/v2.0/events/";
    
        String readableId = "d365mkt";
    
        String token = "abcdef";
    
        String API = endPoint   readableId   "/registrations?emApplicationtoken="   token;
    
        try 
        {
            var req = HttpWebRequest.Create(API) as HttpWebRequest;
            req.ContentType = "application/json";
            req.Method = "Post";
            req.Headers["Origin"] = "http://localhost:8080";
            using (var streamWriter = new StreamWriter(req.GetRequestStream()))
            {
                string json = "{\"attendees\":["  
                                "{"  
                                    "\"firstname\": \"Cloflyy\","  
                                    "\"lastname\": \"Maoer\","  
                                    "\"email\": \"clofly@123.com\","  
                                    "\"passId\": \"\","  
                                    "\"wailisted\": false,"  
                                    "\"autoRegister\": false,"  
                                    "\"responses\": [],"  
                                    "\"attendeeSessions\": [],"  
                                  "}"  
                                "]"   
                               "}";
    
                streamWriter.Write(json);
            }
    
            var response = req.GetResponse();
            
            var encoding = ASCIIEncoding.ASCII;
    
            using (var reader = new System.IO.StreamReader(response.GetResponseStream(), encoding))
            {
                string responseText = reader.ReadToEnd();
                Console.WriteLine(responseText);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    
    }

    Result:

    pastedimage1595555839466v1.png

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,074 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,900 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans