web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
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.

I have the same question (0)
  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    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

  • FlowerPi Profile Picture
    35 on at

    Hi Clofly,

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans