<ConnectionManager Name="Webex" RuntimeVersion="" Help="http://www.cozyroc.com/ssis/webex-connection" xmlns="http://www.cozyroc.com/schema/rcm-config-1.0.xsd">
	<Service EndPoint="https://[Domain]/v1" />

	<Authentication>
		<Documentation>https://developer.webex.com/docs/integrations</Documentation>

		<User>
			<Parameter Name="scope" Default="spark:kms meeting:schedules_read spark:devices_read cjp:config cjp:config_write cjp:config_read spark:people_read cjp:user">
				<Documentation>Specify application client secret. Optional.</Documentation>
			</Parameter>
		</User>

		<Test Url="https://webexapis.com/v1/devices" />

		<Token Url="{{=OAuth2.sign_in_url}}" Result="{{=response.access_token}}">
			<Documentation>https://developer.webex.com/docs/integrations</Documentation>

			<Parameters>
				<Parameter Name="client_id" Value="{{=OAuth2.client_id}}" />
				<Parameter Name="response_type" Value="code" />
				<Parameter Name="state" Value="{{=Math.random()}}" />
				<Parameter Name="scope" Value="{{=token.scope}}" />
				<Parameter Name="redirect_uri" Value="{{=OAuth2.redirect_uri}}" />
			</Parameters>

			<Authorized Id="{{=OAuth2.redirect_uri}}" Result="{{=connection.execute({
				url: OAuth2.authorization_url,
				method: 'POST',
				parameters: {
					grant_type: 'authorization_code',
					client_id: OAuth2.client_id,
					client_secret: OAuth2.client_secret,
					code: response.code,
					redirect_uri: OAuth2.redirect_uri
				}
			})}}" />

			<Refresh Url="{{=OAuth2.refresh_token_url}}" Method="POST" Result="{{=response.refresh_token}}" Expiration="{{=Date.now() + (response.expires_in - 300) * 1000}}">
				<Documentation>https://developer.webex.com/docs/integrations</Documentation>

				<Parameters>
					<Parameter Name="grant_type" Value="refresh_token" />
					<Parameter Name="refresh_token" Value="{{=token.Refresh}}" />
					<Parameter Name="client_id" Value="{{=OAuth2.client_id}}" />
					<Parameter Name="client_secret" Value="{{=OAuth2.client_secret}}" />
				</Parameters>
			</Refresh>
		</Token>

		<Parameters>
			<Parameter Name="Authorization" Value="Bearer {{=token.Access}}" Type="HttpHeader" />
		</Parameters>
	</Authentication>

	<Resources>
		<Template>
			<Field Name="ShortText" DataType="DT_WSTR" Length="255" />
			<Field Name="LongText" DataType="DT_WSTR" Length="1000" />
			<Field Name="DateTime" DataType="DT_DBTIMESTAMP" />
			<Field Name="Date" DataType="DT_DBDATE" />

			<Resource Name="Base">
				<Read>
					<Parameters>
						<Parameter Name="page" Value="{{=parameters.iterator}}" />
						<Parameter Name="per_page" Value="{{=parameters.batchSize}}" />
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
					</Parameters>

					<Iterator>
						<Next Value="{{=parseInt(parameters.iterator || 0) + 1}}" />
					</Iterator>
				</Read>

				<Create Method="POST">
					<Parameters>
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
						<Parameter Name="application/json" Value="{{=Acumatica.getParameterBody(item)}}" Type="Body" />
					</Parameters>
				</Create>

				<Update Method="PUT">
					<Parameters>
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
						<Parameter Name="application/json" Value="{{=Acumatica.setParameterBody(item)}}" Type="Body" />
					</Parameters>
				</Update>

				<Delete Method="DELETE">
					<Parameters>
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
						<Parameter Name="application/json" Value="{{=Acumatica.setParameterBody(item)}}" Type="Body" />
					</Parameters>
				</Delete>
			</Resource>
		</Template>
	</Resources>
	<Script>
		<Module Name="Main">
			<![CDATA[
require('underscore');


]]>
		</Module>
		<Module Name="OAuth 2">
			<![CDATA[
// See RFC 6749 (https://tools.ietf.org/html/rfc6749) for familiarizing with OAuth2 authorization flows-related terms and concepts 
var OAuth2 = {
	client_id: "C3e8f40e512fe33f8a09a618623e01e1d4b4ef233ef224ffb09ca523f39134a23", // required. The Client ID.
	client_secret: "707515cd3cab69023ae09a17026c60e12dd6c8288e1b3c65f832d7cae851fa47", // required. The Client Secret.
	sign_in_url: "https://webexapis.com/v1/authorize", // required. The starting endpoint in the authorization server. 
	sign_in_response_type: "code", // optional. The value for the "response_type" parameter in the initiating call. Usually "code", but can also be "token", "id_token".
	authorization_url: "https://webexapis.com/v1/access_token", // required. The endpoint for exchanging authorization code for an access token.
	authorization_method: "POST", // required. Usually the authorization URL is accessed via a POST request.
	redirect_uri: "https://www.cozyroc.com/oauth_callback", // required. The callback URL to be called after autherization. If the default value doesn't meet requirements, need to setup "Token.Authorized.LocalListenUrl".
	grant_type: "authorization_code", // optional. Can also be "client_credentials" or "password" (see https://auth0.com/docs/applications/reference/grant-types-available )
	refresh_token_url: "https://webexapis.com/v1/access_token" // required, if the authentication needs to support renewing access tokens
};
]]>
		</Module>
	</Script>
</ConnectionManager>