RamBase C# SDK

The RamBase Api can be accessed using the RamBase Api SDK for C#. This can simplify access to RamBase because the SDK can convert the resulting data to objects.

If you want access to the RamBase C# SDK, you can contact us and we will send it to you. We have versions of the SDK for both .Net 3.5 and .Net 4.5. The biggest difference between the versions are that dynamic objects are missing in the .Net 3.5 version.

Below you can see an example of how to get started using the SDK.

Quick start code example

// You should have been assigned a ClientID and a ClientSecret. Replace the 
// appropriate values with your assigned values.
string clientID = "YourClientID";
string clientSecret = "YourClientSecret";

// The SDK expects you to provide your assigned clientID and clientSecret, so that we
// can control what applications are using the Api.
RambaseApi api = new RambaseApi(clientID, clientSecret);

// The Login method performs an attempt to authenticate against Rambase. When logging
// in you should provide a valid Rambase username and password. The result is an
// ApiResponse, which contains information about the result of the request.
ApiResponse response = api.Login(username, password);

// You should always check if the login attempt was OK or not. The HasErrors field is
// set to true if the login failed, and a more detailed message can be found in the
// ErrorMessage field.
if (response.HasErrors)
{
    throw new Exception("Login error. " + response.ErrorMessage);
}

// When we have successfully logged in, we can start doing requests towards the api.
// First we define which resource we want to access.
string uri = "sales/orders?$format=json";

// SendRequest attempts to access the specified resource. Here we say that we want to
// perform a Http GET against the uri "sales/orders?$format=json"
response = api.SendRequest(APIResourceVerb.GET, uri);

// After a request has been made, we want to check for errors in the same way as when
// logging in. The field HasErrors is set to true if the request contains errors, and
// a more detailed error message can be found in the ErrorMessage field.
if (response.HasErrors)
{
    throw new Exception("Request error. " + response.ErrorMessage);
}

// At this point we know that the request went well, so now we can convert the result
// of the request to a dynamic object to process the result. 
// Remember that for ToDynamic() to work, the request must be performed with the 
// format set to json ($format=json). 
// For .Net 3.5 users, we have the option to convert it to a C# class using the 
// ToObject<T>() method
dynamic result = response.ToDynamic();

// We can now access the SalesOrders object that is returned from the resource.
// The names and structure of the output can be found in the documentation
// page for the resource, which for this example can be found here:
// https://api.rambase.net/documentation/tagview/?resourceno=604&status=4
dynamic salesOrders = result.SalesOrders;

// Since this was a list resource, we can now loop through all returned objects,
// and access their properties
foreach(var salesOrder in salesOrders)
{        
    Console.WriteLine("SalesOrderId: " + salesOrder.SalesOrderId);        
    Console.WriteLine("ObjectStatus: " + salesOrder.ObjectStatus);                
    Console.WriteLine("SalesOrderObjectReference Key: " 
                + salesOrder.SalesOrderObjectReference.Key);        
    Console.WriteLine("SalesOrderObjectReference ObjectType: " 
                + salesOrder.SalesOrderObjectReference.ObjectType);        
    Console.WriteLine("SalesOrderObjectReference ObjectId: " 
                + salesOrder.SalesOrderObjectReference.ObjectId);        
    Console.WriteLine("SalesOrderObjectReference ObjectLink: " 
                + salesOrder.SalesOrderObjectReference.ObjectLink);
    Console.WriteLine();
}