Sample c# code
OVERVIEW
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
namespace CollaborateRestClient
{
class Program
{
static void Main(string[] args)
{
string uri = "https://collaboratev3.highqsolutions.com/collaboratev3/api/1/files/686";
try
{
var webRequest = (HttpWebRequest)WebRequest.Create(uri);
//this is the default method/verb, but it's here for clarity
webRequest.Method = "GET";
webRequest.Accept = "application/xml";
webRequest.Headers.Add("Authorization", "Bearer yourauthcodegoeshere ");
webRequest.Headers.Add("Auth-Type", "OAUTH2");
var webResponse = (HttpWebResponse)webRequest.GetResponse();
String responseString;
using (Stream stream = webResponse.GetResponseStream())
{
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
responseString = reader.ReadToEnd();
}
Console.WriteLine(responseString);
}
catch (WebException ex)
{
Console.WriteLine("Error occured:" + ex.ToString());
}
}
}
}
This was a bug in my code. I stepped through the code and discovered that I was still calling a GET request. I was trying to create a new folder in an existing site, not add a user. I was successful at the POST request to create a folder. Thank you.
Shawn Rupert , Digby Field are you trying to add a user at system level or site level? Can you share the REST API end point you are using in your call. Thanks
Shawn Rupert I'm using webRequest.ContentType = "application/xml" and webRequest.Accept = "application/xml". I managed to get it working, my XML data was UTF-16, not 8.
Digby, are you setting request.Accept = "application/JSON" and request.ContentType = "application/JSON" or both to application/XML? Maybe that is the issue for you. I am getting 405, method not allowed with my C# application.
It would be useful if you could provide a c# example of post - I am getting (400) Bad Request every time. I can GET lists of user and groups with no problem
Shawn Rupert from 4.3 we are providing postman scripts for implemented methods so you can check those out in the documentation. We have no plans to provide examples in each coding language. We are looking into using Swagger to provide samples, but it's going to be sometime before we do that.
Can you add examples for other methods, POST, PUT, DELETE?
Comments
7 Comments