I am working with eloqua 10.
I need to create Email in eloqua by using their rest api from an aspx web page.But am get 404 Bad Request
.
Given below is the code sample for the POST request that I tried.
string authenticateStr = eloquainstance + @"\" + username + ':' + password;
byte[] bytesToEncode = Encoding.UTF8.GetBytes(authenticateStr);
string encodedText = Convert.ToBase64String(bytesToEncode);
string requrl = "/assets/email";
string requestBody = "<subject>Test subject</subject>" +
"<senderName>Ajai Test</senderName>" +
"<senderEmail>amani@suyati.com</senderEmail>" +
"<emailGroupId>9</emailGroupId>" +
"<htmlContent>This is a test email templete created trough rest api.This is for testing purpose only</htmlContent>"+
"<type>Email</type>" +
"<name>Email By api</name>";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(baseurl + requrl);
request.Headers.Add("Authorization", "Basic " + encodedText);
request.Accept = "application/xml";//"application/x-www-form-urlencoded";
request.Method = "POST";
request.ContentType = "application/xml";
request.ContentLength = requestBody.Length;
//write body to text
byte[] body = System.Text.Encoding.UTF8.GetBytes(requestBody);
Stream dataStream = request.GetRequestStream();
dataStream.Write(body, 0, requestBody.Length);
dataStream.Close();
HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();
Please correct me if anything wrong in my code.
Can anybody tried a post using eloqua rest api, if so can you share a sample code to make a POST request to eloqua from c#.Any help be appreciable.