How to use SuperOffice.WebApi
In just a few simple steps you can get ready to work with the web service agents:
- Obtain OAuth tokens.
- Instantiate a
WebApiOptions
object. - Define the IAuthorization credential type.
- Create the desired Agent class, passing in the
WebApiOptions
as a constructor parameter.
Instantiate a WebApiOptions object
WebApiOptions(string baseUrl);
The primary constructor accepts the target WebApi URL, https://sod.superoffice.com/cust12345/api
, which is available as a claim in the ID token and system user token.
WebApiOptions
inherits from RequestOptions, which contain the internationalization settings. These settings can also be passed into the overloaded constructor.
WebApiOptions(
string baseUrl,
IAuthorization authorization,
string languageCode = null,
string timeZone = null,
bool verifyUrl = true
);
Define the IAuthorization credential type
The IAuthorization parameter is used to define the credential type and to set the Authorization attribute in each HTTP request.
Assign an instance to the WebApiOptions.Authorization
property.
Alternative 1:
var auth = new AuthorizationUsernamePassword("jack@black.com", "TenaciousD!");
var config = new WebApiOptions(tenant.WebApiUrl, auth);
Alternative 2:
var config = new WebApiOptions(tenant.WebApiUrl);
config.Authorization = new AuthorizationUsernamePassword("jack@black.com""TenaciousD!");
Create and use the desired Agent
To create an Agent object, pass in the WebApiOptions
as a constructor parameter.
var contactAgent = new ContactAgent(config);
Note
This is the only Agent difference when compared to using the existing WCF SOAP proxies.
Now your code can make the same calls as before. The biggest change is that they are now asynchronous and can use the async-await pattern!
public async Task<ContactEntity> GetContactEntity(contactId)
{
return await contactAgent.GetContactEntityAsync(contactId);
}