You often need to add specific HTTP headers to your request. For example, some APIs require you to pass the version number of the API you are going to use in a custom header field (e.g. API-VERSION). You may also need to add standard HTTP headers such as Authorization.
Note that Content-Length and Content-Type is automatically set for you based on the contents you added to the request body (adding contents to the request body will be discussed next).
To add a header to your request, use the AddHeader method of the Options object.
#Request.Options.AddHeader Name('API-VERSION') Value('2.0')
For the Authorization header, there are two methods provided for your convenience (which are basically just shortcuts for manually invoking AddHeader):
Basic Authorization
Basic Authorization uses username and password for authentication and authorization of resources. It is not common to see APIs that would use this authorization method. Most services would either use API keys or access tokens.
Example of usage:
#Request.Options.AddBasicAuthorization UserName('my-username') Password('my-password')
Authorization using Bearer Token
Bearer tokens allow access to protected resources. The token contains the complete information (in an encrypted form) of what resources it allows to access (unlike a session key, which is simply a key, and on its own does not mean anything).
#Request.Options.AddBearerAuthorization Value('token')
As a bearer token is the actual representation what resources the bearer can access, it does not have a fixed length. Tokens from the same service can vary in length, and they can be very long. Bear this in mind when you are passing the value around using fields, make sure that your fields are long enough the hold the full length of the token.