> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to use SuperOffice.WebApi

> How to use SuperOffice.WebApi

In just a few simple steps you can get ready to work with the web service agents:

1. [Obtain OAuth tokens][3].
2. Instantiate a `WebApiOptions` object.
3. Define the [IAuthorization credential type][1].
4. 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.

```csharp theme={null}
WebApiOptions(
  string baseUrl,
  IAuthorization authorization,
  string languageCode = null,
  string timeZone = null,
  bool verifyUrl = true
);
```

## Define the IAuthorization credential type

The [IAuthorization][1] 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:**

```csharp theme={null}
var auth = new AuthorizationUsernamePassword("jack@black.com", "TenaciousD!");
var config = new WebApiOptions(tenant.WebApiUrl, auth);
```

**Alternative 2:**

```csharp theme={null}
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.

```csharp theme={null}
var contactAgent = new ContactAgent(config);
```

<Note>
  This is the only Agent difference when compared to using the existing [WCF SOAP proxies][2].
</Note>

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!

```csharp theme={null}
public async Task<ContactEntity> GetContactEntity(contactId)
{
  return await contactAgent.GetContactEntityAsync(contactId);
}
```

[1]: ./iauthorization

[2]: ../built-in

[3]: https://www.nuget.org/packages/AspNet.Security.OAuth.SuperOffice/


## Related topics

- [How to get a system user ticket credential](/en/api/authentication/online/auth-application/get-system-user-ticket.md)
- [How to create a user-defined field using the web services API](/en/api/web-services/howto/custom-objects/rest-create-udef-field.md)
- [How to update a user-defined field using the web services API](/en/api/web-services/howto/custom-objects/rest-update-udef-field.md)
- [How to get all user-defined fields using the web services API](/en/api/web-services/howto/custom-objects/rest-get-all-udef-fields.md)
- [SuperOffice.WebApi.Data.UserPreferenceStrings.System](/en/api/reference/webapi/SuperOffice.WebApi.Data.UserPreferenceStrings.System.md)
- [SuperOffice.WebApi.Data.UserPreferenceStrings.Functions](/en/api/reference/webapi/SuperOffice.WebApi.Data.UserPreferenceStrings.Functions.md)
