Admin Portal Guide

Red Hat 3scale 2-saas

Manage aspects related to Red Hat 3scale.

Red Hat Customer Content Services

Abstract

This guide provides the information to manage Red Hat 3scale.

Preface

This guide will help you to use the available functions in the Admin Portal to manage your 3scale installation.

Part I. Account settings

Chapter 1. Account configuration

After creating your account, update basic information about your company. Set your location and add your contact information.

Note
The account view is only visible to admins (and not to members).

1.1. Add your company information

Once you have created your new account, click on the gear icon in the top navigation bar, and then on Account → Overview and click on Edit in the Details item. Fill in the information for your account.

Account configuration

The address you write here is what we use for billing purposes (if you are on a paid plan) and also what your user will see on your invoices if you’re using the billing and payments modules.

1.2. Select your preferred time zone

On the same page you can also select the time zone you will use on all system displays. This setting affects analytics graphs. However, billing cycle calculations are made according to UTC time.

Chapter 2. Red Hat Single Sign On for the 3scale Admin Portal

This guide provides information about how to configure and use Red Hat Single Sign On (RH SSO) with the 3scale Admin Portal.

2.1. Enable RH SSO or Auth0 member authentication

3scale supports single sign on (SS0) authentication for your members and admins.

The 3scale Admin Portal supports the following SSO providers, each which support a number of identity brokering and member federation options:

Note

You can enable multiple SSO member authentication types

Only users that have been added to RH SSO or Auth0 will be able to access your 3scale Admin Portal through SSO. If you want to further restrict the access by either roles or user groups you should refer to the corresponding step by step tutorials on the RH SSO or Auth0 support portals.

Once you have established SSO through your chosen provider, you must configure it and enable it on the 3scale Admin Portal.

2.1.1. RH SSO prerequisites

2.1.2. Auth0 prerequisites

  • An Auth0 Subscription and account

2.1.3. Enable RH SSO

As an administrator, perform the following steps in the 3scale admin panel to enable RH SSO or Auth0:

  1. Ensure your preferred SSO provider, highlighted in the prerequisites, has been properly configured
  2. Navigate to SSO Integrations in the Account Settings:

    • Click the gear icon in the upper right corner of the page
    • Navigate to Account Settings (gear icon) > Users > SSO Integrations, and click New SSO Integration.
  3. Select your SSO provider from the dropdown list
  4. Enter the required information, provided when you configured your SSO:

    • Client
    • Client Secret
    • Realm or Site
  5. Click Create Authentication Provider
Note

If, during testing, you encounter a callback URL mismatch, add the callback URL shown in the error message to your Auth0 allowed callback URLs.

2.2. Using RH SSO with 3scale

Once you have configured SSO, members can sign on using the account credentials in connected IdPs.

Follow these steps to log in to the 3scale Admin Portal using SSO:

  1. Navigate to your 3scale login page:

    https://<organization>-admin.3scale.net/p/login
  2. Authorize 3scale with your IdP
  3. If necessary, complete sign up by entering any needed information

Once you successfully sign up, you will have a member account under the API provider organization, and you will be automatically logged in.

2.3. Redirecting a 3scale login to a RH SSO option

These steps will show the 3scale API Management administrator how to redirect to an Identity Provider (IdP) login screen (RH SSO). Complete these steps and your 3scale account will be accessible through an optional single sign-on (SSO) login page.

2.3.1. Prerequisites

  • 3scale 2-saas
  • An RH SSO instance and realm configured as described under the Configuring RH SSO section of the Developer Portal authentication documentation.
Note

Before you can integrate RH SSO with 3scale, you must have a working RH SSO instance. Refer to the RH SSO documentation for installation instructions: Installing RH-SSO 7.2.

2.3.2. Required steps

  1. Access and follow the instructions for setting up RH SSO under the Red Hat Single Sign On for the 3scale Admin Portal section of the 3scale documentation.
  2. Provide your RH SSO administrator with your 3scale URL. The URL will form the basis for a redirect within RH SSO for your secure logon.

    https://<organization>-admin.3scale.net/auth/<system_name>/bounce
  3. The system_name assumes RH SSO has been used as the SSO provider in your 3scale instance with an id of rhsso:

    https://<organization>-admin.3scale.net/auth/rhsso/bounce
  4. To get the id in your 3scale instance navigate to:

    https://<organization>.3scale.net/p/admin/account/authentication_providers/<ID>
  5. You will see:

    • The Callback URL

      https://<organization>.3scale.net/auth/keycloak_0123456aaaaa/callback
    • Where keycloak_0123456aaaaa is the system name and is used in the bounce URL.
  6. Navigate to the new RH SSO URL and securely log in to your 3scale account.

Chapter 3. Inviting users and managing rights

In order to share the workload of administering your APIs, you may wish to invite team members from your organization to access the 3scale Admin Portal. In this tutorial, you’ll see how to that and what types of roles and rights are available. Note: The 'invite' feature is only available for Pro and Enterprise customers.

The instructions below describe how to give access rights to the 3scale Admin Portal. to one or more team members.

3.2. Send an invitation

You can find invitations in Users > Invitations.

Sending invitation

Enter the email address of the person you want to invite and click send. An invitation email will be sent to the address you entered. If the email doesn’t arrive, make sure it didn’t get marked as spam.

3.3. Accept the invitation

Your new administrator or member must click the link in the invitation email and complete the form to complete the process. Once the form is submitted, their account will be activated.

3.4. Give new users rights

There are two main type of rights you can give to members of your team:

  • By area: Such as analytics, billing, or developer administration.
  • By service: Choose which services to give access to members amongst all of your services. Note: This feature is only available for enterprise customers.

To give a new user rights, edit the new user by selecting them from the user menu and clicking on Edit.

Changing their rights to “admin” will give them full access to control the Admin Portal.

Changing their rights to "member" will give you the option of choosing which areas and services the team member has access to.

Rights by area and service

Giving access to certain areas of the Admin Portal will give members access only to the equivalent API:

  • Developer accounts — Applications: Gives access to the Account management API
  • Analytics: Gives access to the Analytics API
  • Billing: Gives access to the Billing API

Chapter 4. Notifications

Notifications are sent to admins and members to make it easier to parse developer activity (new account

4.1. Types of notifications

There are different types of notifications:

  • Accounts
  • Billing
  • Applications
  • Service subscriptions
  • Usage alerts

4.2. Visibility

Admin users have access to all notifications.

Member users have access only to notifications of the areas they have been given access to. For example, a member will only have access to notifications related to billing if they have access to the billing section.

For enterprise accounts, member users will only have access to notifications regarding activity of the services they have been granted access to.

4.3. Subscribing to notifications by email

Subscriptions are personal and can only be modified by the person receiving those notifications. To edit your subscriptions:

  1. Navigate to Account Settings (gear icon) > Personal > Notification Preferences.
  2. Check the notifications you would like to receive.
Manage notifications

4.4. Web notifications

In addition to email notifications, these can be found in your Dashboard:

Accounts dashboard

Chapter 5. Personal settings

In Personal settings you can edit your preferences as a team member. If you’re an admin, you will also be able to edit the account preferences. For that, check out the account configuration tutorial.

5.1. Types of settings

There are 3 types of settings you can edit from here

  • Personal Details: Name, email, password, etc.
  • Tokens: Create access tokens to authenticate against the 3scale APIs – Billing, Account Management, and Analytics – and try them out using our ActiveDocs (interactive documentation). Learn more about 3scale tokens.
  • Notification Preferences: Select which notifications you’d like to receive. Note: If you’re an enterprise customer, and if you are a member, these are filtered by area and service. This means you’ll only be able to subscribe to notifications re: areas and services you’ve been given access to. More on notification preferences here.
Personal settings

Chapter 6. Tokens

This tutorial contains information about 3scale tokens: what are they, how they work, and how to create them.

3scale has two types of tokens: Access tokens (created by the user) and Service tokens (automatically created when you create a new service in 3scale).

6.1. Access tokens

Access tokens allow API provider admins and members to authenticate against the 3scale APIs – Billing, Account management, and Analytics – and try them out using our ActiveDocs (interactive documentation).

An access token may provide either read and write access, or read only.

An important thing to take into account is how access tokens work, which is according to the member’s rights. Admins can create tokens to authenticate against all three 3scale APIs. Members will be limited by their permissions to access the different parts of the Admin Portal. For example, if a member doesn’t have access to the Billing area, they won’t be able to create a token to authenticate against the Billing API.

6.2. Creating access tokens

Access tokens can be created on the tokens page. To access the tokens page, click on the gear icon in the upper right corner of the page, and then navigate to Personal > Tokens.

Access tokens screen

Click on Add Access Token and choose a name, scope, and permissions.

New access token

Note that if you are a member, you might not see all the APIs – just the ones you’ve been given access to by the admin of your account.

You can create as many access tokens as you need, but take into account that for security reasons, they won’t be stored on 3scale. When you create a new token, you’ll be alerted to save the token so you can then use it to make requests to the 3scale API. If you lose a token, we recommend that you delete it – which will disable it and render it invalid – then create a new one.

6.3. Using access tokens

When using your access token to make calls to the 3scale APIs the results will be filtered by the services you have access to.

For example, when deploying APIcast self-managed, you’ll need an access token so your APIcast API gateway can pull the configuration of the service using the Account Management API.

The way it works is if your organization has set up three services on 3scale, and as a member, you have access to Service 1, but not 2 and 3, and you also have access to the Account Management API, when you create a token and make a request to the Account Management API you will only get the applications which are using Service 1.

Following the same example, if you have access to the Account Management API, but access to zero services, when making a call, you’ll get "access denied" error.

6.3.1. Service tokens

Service tokens are used to authenticate against 3scale Service Management API. Service tokens are generated automatically when a new service is created in 3scale, and are unique per service. They are shared among the users of the 3scale account. You can find the service tokens for the services that the user has access to in the Admin Portal’s Dashboard: Account Settings (gear icon) > Personal > Tokens.

Service tokens

Part II. Access control

Chapter 7. Defining your API (Methods And Metrics)

To define your API on 3scale, navigate to [Your_API_service] > Integration > Methods & Metrics and add your methods and metrics.

Metrics lets you track the usage of your API in 3scale. Hits is the built-in metric, it exists in each API service and is used to track the hits made to your API. You can achieve finer granularity for the API usage tracking by defining Methods under the Hits metric. Reporting traffic to a method will increase counters for the method and for the Hits metric automatically. You can define separate methods for each endpoint of you API, or a combination of endpoint and HTTP method. See Mapping rules section to learn how to map the endpoints of your API to the methods defined here.

For measuring usage of your API apart from hits, you can define a new Metric and report the usage in different units. A unit should be quantifiable and apply a meaning for your business goals such as megabytes, CPU time, the number of elements returned by the API, etc. All metrics other than hits, such as CPU time or mb, are not included by default on 3scale and must be reported using an Endpoint periodically called by an external Service configured by the user.

Methods and metrics are also the scaffolding to package your API: each application plan lets you define different usage limits and pricing rules for each method and metric.

You will be able to see the the usage reported to metrics and methods in the Analytics section.

7.1. Manually add methods and metrics

  1. Navigate to [Your_API_name] > Integration > Methods & Metrics.

    New Method New Metric
  2. Click on New method.
  3. Specify the parameters:

    • Friendly name is a short description of the method, it is shown in different sections of the 3scale Admin Portal. This name must be unique for the service.
    • System name is the name of the method which will be used to report the usage through 3scale Service Management API. It also must be unique, and it should only contain alphanumeric characters, underscore _, hyphen - and forward slash / without spaces. Other than that, you are free to decide how the system name will look like, it can be exactly the same as the endpoint ("/status"), or for example can include the method and the path ("GET_/status").
    • The Description field can be used for a more detailed description of the method, it is optional.

      New Method Details
  4. Finally, click on Create Method button.

You can later change the definition of the method. Just click on the method name (in the column Method), update the fields and click on Update Method.

Be very careful with changing the system name of the methods and metrics or deleting them! It may break your already deployed 3scale integration, if there are mapping rules poining to the previous system name of the method.

For creating a new metric, click on New metric and provide the required parameters. When specifying the unit, use singular noun (e.g. "hit"), as it will be pluralized automatically in the Analytics charts.

These new methods and metrics will be available in all your current and future plans. You can now edit limits and pricing rules for them on each plan going to [Your_API_service] > Applications > Application Plans > [plan_you_want_to_edit].

7.2. Import your methods and metrics automatically

If your API has a lot of endpoints, we offer two additional ways of automatically creating your methods and metrics on 3scale:

Chapter 8. Application plans

Application Plans define the different sets of access rights you might want to allow for consumers of your API. These can determine anything from rate limits, which methods or resources are accessible and which features are enabled.

8.1. How to create an application plan

By default, when your 3scale account is created, you are given two plans: Basic and Unlimited. You can keep and edit these or create your own. You can create as many plans as you need.

To create a new application plan, follow these steps:

  1. Navigate to [Your_API_service] > Applications > Application Plans.
  2. Click ‘Create Application Plan’.
Create new plans

In the next screen, pick a name and a system name (system names must be unique) for your new plan. If the Applications require approval? checkbox is selected, no applications will be able to access your API without approval.

Publish new plan

Once you have created a plan, you can provision rate limits and set up paid plans.

8.2. Setting up a default application plan

After you have created all your plans, you can select a default plan for when people sign up to register their applications. To do so, navigate to [Your_API_service] > Applications > Application Plans, and select the default plan:

Default plan

If you don’t indicate a default application plan, when a new user signs up to get access to your API, they won’t be created an application by default (meaning they won’t really get access to your API).

Chapter 9. Mapping rules

After defining your API creating methods and metrics, you can map your API endpoints or paths to the methods you have defined in the Definition page. To do so:

  1. Navigate to [Your_API_service] > Integration > Configuration > Edit APIcast configuration and find the Mapping rules section in the page.
  2. Choose the HTTP method, available on the specific endpoint path
  3. Select the equivalent method to map against. Different operations (GET, PUT, POST, DELETE, etc…​) on the same endpoint can be tracked separately.

The workflow to define mapping rules is as follows:

  • Add new rules by clicking on Add Mapping Rule link. Then select an HTTP method, a pattern, a metric (or method), and its increment. When you’re done, click the Update & Test Staging Configuration button.

    mapping rules
  • Mapping rules will be grayed out on the next reload to prevent accidental modifications.
  • To edit an existing mapping rule, you must first enable editing by clicking on the pencil icon on the right. To delete a rule, click on the red trash icon. Edits, modifications, and deletions will be saved when you hit the Update & Test Staging Configuration button.

Once the setup is done, you can test your integration with the Staging APIcast Cloud Gateway to ensure your setup will work in production.

If all the parameters and mapping rules are set correctly, you should see a green line showing a correct test integration between 3scale and your API Backend.

3scale API gateway staging

Chapter 10. Provisioning paid plans

One of the most popular ways to monetize an API is by defining subscription fees based on usage. This section focuses on how to use application plans to provision pricing tiers. It’s also possible to apply pricing rules at the account and the service level – these topics are covered in advanced guides.

Below you’ll learn about the pricing options for application plans and how to set up a paid plan.

10.1. Make decisions about your pricing model

The first decision to make is how to differentiate between the tiers in your pricing model. Will the tiers be driven by volume/usage, API functionality, access to other resources, or a combination?

  • Volume / Usage. The most common way to differentiate between tiers is based on volume because volume usually has a strong correlation to value to the customer as well as cost to serve. You can apply a global hit count for calls on the API or a more granular measurement at the method level.
  • Functionality. You can enable or disable access to parts of your API depending on the tier. This is a good approach to distinguish between standard and premium levels.
  • Resources. You can also create tiers based on access to any other resources that provide value to the customer or drive costs in your infrastructure – for example, GB’s of bandwidth consumed, number of users, or transaction values.

Once you have decided on your pricing drivers, you must decide whether the tiers will be based on a flat rate subscription, a variable rate, or a one-off upfront charge. All three of the pricing drivers above are compatible with the one off, or monthly flat rate subscriptions. If you decide your pricing will be based on volume of hits or resource consumption, there will of course be a variable element to your pricing.

10.2. Set up an application plan with your pricing rules

You can either create a new application plan or edit an existing one. When creating a new application plan, you can enter any upfront charges or flat rate subscriptions.

Create new application plan or edit existing

In the edit application view, you can enter or modify the upfront charges and subscriptions.

Next, set up the pricing drivers you decided on in step 1. If some of them already exist as metrics, you can simply edit the item.

  • Volume drivers: are applied at the level of the global hits metric, or for individual methods under hits. Multiple pricing rules can be applied to any metric. Note that the hits calculation is cumulated over a one-month billing cycle.
  • Functionality drivers are set by enabling or disabling the metric for this plan.
  • Resource drivers are similar to volume drivers but are applied on custom metrics.
Setup pricing driversin application plan
Zoom in to edit pricing rule in application plan

Once you’re finished setting up your pricing rules, be sure to click “update application plan”.

10.3. Create further pricing tiers

It’s ok to define an API paid plan with a single application plan. Usually this would be the case if all your pricing rules are defined by volume or resource drivers. However if you want to offer separate plans for different segments of your developer community, you’ll need to add more application plans.

The easiest way to do this is to copy the first application plan from the application plan overview page. This way, it will be pre-populated with all the existing metrics and pricing rules. The more care you take to create a full plan the first time, the more time you will save with the plan copy feature.

10.4. Provision the paid plans

In order to provision the plans, your developers must create new applications and select one of the new paid plans. You can also do this on their behalf from the admin console. For any existing applications, it’s also possible to change from an existing plan to one of the new paid plans.

10.5. More information

In conjunction with flat-rate pricing plans it’s common to differentiate between tiers using rate limits. This is explained in provision rate limits

Chapter 11. Provisioning rate limits

Rate limits allow you to throttle access to your API resources. You can configure different limits for separate developer segments through the use of application plans.

Once you have rate limits in place, these limits will control the responses a developer receives when they make authorization request calls to the 3scale back end.

11.1. Go to the application plan

If you do not have an application plan defined yet, create one first. Otherwise, select the plan you want to set rate limits for and click edit.

Rate limits

11.2. Set the rate limits

New usage limit

11.3. Update the application plan

When you are finished setting the limits you require, save your changes by clicking Update Application plan.

11.4. Put the new rate limits into action

Now that you have your rate limits defined, the following will happen:

  • If you have alerts configured, the new limits will be used to decide when notifications are sent.
  • When you make authorization calls to the 3scale back end, the limits will be taken into account and the response will be with status code 409. In this case the APIcast API gateway sends a response to the client with the status code 429 Too Many Requests and the message, Limits exceeded.

Once your rate limits are operational, you will see the users who are reaching the limits on your dashboard, making it quick and easy to check for potential plan upgrade candidates.

Note

For more information about soft and hard limits, you should read 1.1.3.2. Configure your API access policies with application plans, window="_blank" in our Quickstart guide.

Dashboard messages

11.5. More information

Besides setting rate limits, you can also set variable pricing rules for the same metrics – see provision paid plans

Part III. Billing

Chapter 12. Configuring Billing Settings

This document describes how the Billing feature works in 3scale.

Billing settings are divided into Charging & Gateway and Credit Card Policies, both can be found in Audience > Billing in the Admin Portal.

12.1. Billing modes (Charging & Gateway)

Billing in 3scale is based on the calendar month, and can be Prepaid and *Postpaid.

  • In the Prepaid mode, all fixed fees and setup fees are billed at the beginning of the month or at the beginning of any prorated billing period. Variable costs are always calculated and billed at the beginning of the following month.
  • In Postpaid mode, all fixed fees as well as variable costs are billed at the beginning of the following month.

For more details see Automated billing process.

12.2. Charging enabled (Charging & Gateway)

This setting enables credit card transactions. When this setting is on, all due invoices will be charged using the selected payment gateway. If you leave this setting off, billing will take place and invoices will be issued, but no real payment transaction will take place.

12.3. Currency (Charging & Gateway)

Select the currency in which billing and the credit card transactions will be made. Please make sure that the selected currency is supported by your payment gateway. This setting is global and applies to all invoices and transactions; it is not possible to set different currencies for different developer accounts.

12.4. Invoice footnote (Charging & Gateway)

The text introduced in the Invoice footnote field will appear at the bottom of every PDF invoice. You can use this field to provide additional information about the charging and billing policy for your customers.

If the text of the footnote is changed, it doesn’t automatically apply to the invoices, for which the PDF has already been generated. However, it is possible to apply the change by regenerating the PDF of the invoices.

12.5. Text to show if VAT/Sales Tax is 0% (Charging & Gateway)

This field is used to add a text message to the PDF invoice, in case VAT / Sales Tax is 0% for the billed account. This line will only appear if the VAT / Sales Tax is set to 0 explicitly, otherwise it will not be shown. This text will also appear on the Invoice page in the Admin Portal.

See more about this setting in VAT / Sales Tax section

12.6. Billing periods for invoice ids (Charging & Gateway)

Invoices in 3scale have two types of IDs:

Actual ID
which uniquely identifies the invoice in the database. This is a numeric ID, which appears in the invoice URL (i.e. https://<dashboard_domain>/buyers/accounts/<acount_id>/invoices/<invoice_id>) and is used as the invoice ID in the Billing API.
Friendly ID
which appears on the invoice, is a user-friendly identifier. It should be unique per 3scale account, although it’s technically possible to have duplicated friendly ID. In case duplicate ID is identified by the system, it will show a warning: "This invoice id is already in use and should probably be changed". If the friendly ID displays as "fix" for more than 24 hours, please contact support.

This setting defines the format of the Friendly ID of the invoice:

monthly (default)
YYYY-MM-XXXXXXXX, i.e. the ID includes the year, the month and the number of the invoice. Example: 2018-02-00000013
yearly
YYYY-XXXXXXXX, i.e. it only includes the year and the number. Example: 2018-00000001

The only effect of changing the Billing periods for invoice ids from "monthly" to "yearly" is changing the friendly ID format, this doesn’t change the billing cycle period, only monthly billing is supported by 3scale API Management. Changing the format of the invoice IDs to yearly can be used, if there is such a requirement from your accounting department.

If you need to charge the customers yearly, billing should be handled manually – you can create a new invoice and add a line item with the yearly cost. If you prefer to use yearly charging, you may also want to set your application plans to be free, to make sure the invoices are not generated and/or charged automatically each month.

12.7. Credit Card Policies

Here you can configure the path to the following pages:

  • Legal Terms page
  • Privacy page
  • Refund page

12.8. Credit Card Gateways

3scale integrates with the following payment gateways for credit card transactions:

  • BraintreeBlue
  • Stripe
  • Adyen
Warning

Authorize.Net and Ogone integrations are deprecated. New integrations are not supported. For integrations existing before 27th July 2018, Red Hat provides support, but recommends to migrate to one of the fully supported payment gateways.

12.8.1. Stripe integration (recommended)

After completing these steps you will have configured Stripe as a payment gateway for your account. This will allow your developers to enter their credit card details, and you can automatically charge them through Stripe for access to your API, according to the calculated invoices.

If you enable credit card charging for your paid API, then one key step is to setup your payment gateway. There are a number of alternative payment gateways which you can use with your 3scale account. Here we cover the steps for Stripe.

12.8.1.1. Prerequisites

Before you start these steps, you will need to open an account with Stripe.

12.8.1.2. Getting your API keys from Stripe

Log in to your Stripe account, and get your API keys at https://dashboard.stripe.com/account/apikeys. You will need two keys: a "secret" one, and a "publishable" one. Use the "test" set when you’re doing tests and the "live" ones when you are ready to start charging.

Stripe Integration

12.8.1.3. Configuring settings in 3scale

You need to tell 3scale to start using these API keys. To do this, log in to your 3scale Admin Portal. and go to Audience > Billing > Charging & Gateway.

Billing page

If the Charging Enabled flag is not active, enable it and click Save.

Enable charging

You should see a drop-down called Gateway near the bottom of the page. Change it to Stripe.

Billing gateway

The form below the drop-down should change to show two fields. Insert your Stripe API keys and click Save.

Stripe billing gateway

You might see a couple of alerts when you change your payment gateway. This is expected. Read them and accept them if they appear.

The payment gateway is now set up, but your users might not be able to use it yet since the it’s not configured in the CMS. Go to Developer portal, and click on the template called Payment Gateway / Show on the left navigation pane.

Developer portal - Billing

If it’s not there already, add the following code before {% when "braintree_blue" %}:

{% when "stripe" %}
 <p><a href="{{ current_account.edit_stripe_billing_address_url }}">Edit billing address</a></p>

 {% if current_account.has_billing_address? %}
   {% stripe_form "Edit Credit Card Details" %}
 {% else %}
   <p>After entering billing address, the option to enter credit card will be enabled.</p>
 {% endif %}

Finally click Save and Publish. Your users should now be able to pay you using the Stripe gateway.

Note

In order to map your data from Stripe with your data on 3scale, you can use the Stripe field called metadata.3scale_account_reference which is composed of 3scale-[PROVIDER_ID]-[DEVELOPER_ACCOUNT_ID]

12.8.2. Adyen integration

After completing these steps, you will have configured Adyen as a payment gateway for your account. This will allow your developers to enter their credit card details, and you can automatically charge them through Adyen for access to your API, according to the calculated invoices.

Setting up your payment gateway is a key step enabling credit card charging for use of your paid API. There are a number of alternative payment gateways you can use with your 3scale account. Here we cover the steps for Adyen.

12.8.2.1. Prerequisites

  • Before you start these steps, you will need to open an account with Adyen.
  • You need a Company account and a Merchant account within it (sub-account).
  • There are a number of requirements that must be fulfilled before you can apply for a live account with Adyen. You can see what those requirements are here.
  • The account should be in production mode.

12.8.2.2. Configuring Adyen integration

Find the information in your Adyen account

  1. To begin, log into your Adyen account. Then find your credentials in the Settings > Users area, and select System from the dropdown menu in the following view:
docs billing Adyen settings
  1. Click on the Company account (the account at the top of the list). You will then be taken to the Company account settings view:
docs billing Adyen view credentials
  1. Finally you have access to the Login, Secret Password, Client Encryption Public Key, Merchant ID, and Library location that you will need for the 3scale billing settings.
  2. To view the Public Key, you must click on Generate Password and copy this password somewhere.
docs billing Adyen credentials

Configure your payment gateway in your 3scale account

  1. In Audience > Billing > Charging & Gateway, enable charging by checking the box and click Save.
  2. You will see all the fields you need to setup to create the link to your Adyen gateway.
  3. You must select Adyen from the Gateway dropdown menu and save changes.
docs billing Adyen settings

Enable the alias additional data in the Adyen API response

By default when credit card authorization requests are sent from 3scale to Adyen, the returned response does not include the unique identifier of the credit card.

To ensure that the correct credit card reference is saved in 3scale and the correct card is charged, this additional data needs to be enabled.

Contact Adyen support to enable the alias additional data in the response for the authorization request.

Test your billing workflow

  1. Make sure you accelerate the test cycle by enabling Prepaid Mode to generate the charge within a day or so.
  2. Then choose an existing test account and create an invoice with a line item charge added.

    1. Charge the account immediately.
    2. This testing approach will incur some minor costs, but it is worth it for the peace of mind that everything works fine, before you have real paying developers using your API.

The payment gateway is now set up, but your users might not be able to use it yet since it is not configured in the CMS. Go to the developer portal tab, and find the template called Payment Gateway / Show on the left navigation pane.

If it is not there already, add the following snippet after the block of code beginning with {% when "stripe" %}

{% when "adyen12" %}
{% if current_account.has_billing_address? %}
  {% adyen12_form %}
{% else %}
  <p><a href="{{ current_account.edit_adyen12_billing_address_url }}">First add a billing address</a></p>
{% endif %}
Note
  • For accounts created before 11th May 2016 you must add the snippet above manually. After said date this will be included in the template by default.
  • In order to map your data from Adyen with your data on 3scale, you can use the Adyen field called shopperReference which is composed of 3scale-[PROVIDER_ID]-[DEVELOPER_ACCOUNT_ID]

12.8.3. Braintree integration

These are the steps to set up the Braintree gateway in order to to charge for use of your API.

12.8.3.1. Getting your API keys from Braintree

You’ll need to open an account with Braintree. You need a Gateway and Merchant account plus Vault. As an optional extra, you can choose to allow American Express cards as a payment method.

To begin, log in to your Braintree account. Then find your API keys in the Account > MyUser area:

Braintree Settings

The API keys page still hides the private key, so select the option to view it:

Braintree keys

Finally you have the Public Key, Private Key, and Merchant ID that you’ll need for the 3scale billing settings:

Braintree keys

12.8.3.2. Configuring settings in 3scale

You need to tell 3scale to start using these API keys. To do this, log in to your 3scale Admin Portal and go to Audience > Billing > Charging & Gateway.

Ensure that the currency type specified on the billing page matches the currency type used in your Braintree merchant account.

Billing

If the Charging Enabled flag is not active, enable it and click Save.

Billing charging enabled

You should see a drop-down called Gateway near the bottom of the page. Change it to Braintree (Blue Platform).

Billing Gateway

The form below the drop-down should change to show two fields. Insert your Braintree keys and click Save.

Ogone billing gateway

You might see a couple of alerts when you change your payment gateway. This is expected. Read and accept them if they appear.

Your users should now be able to pay you using the Braintree gateway.

Note

In order to map your data from Braintree with your data on 3scale, you can use the Braintree field called customer.id which is composed of 3scale-[PROVIDER_ID]-[DEVELOPER_ACCOUNT_ID]

12.8.3.2.1. Troubleshooting

In case your account is in the sandbox mode and you encounter any problems, you will have to change it to production.

Chapter 13. Pricing

This section describes different ways you can charge your developers for using your API.

Setup fee
is a one-time charge applied upon subscription to the service, it is not charged when switching to another plan. It appear in the invoice/credit card only on the first month of a subscription. Can be configured on application plans, service plans, and account plans.
Cost per month
is a recurring cost charged monthly. It is prorated if the subscription occurred in the middle of the month. Sometimes it it referred to as "fixed fee". Can be configured on application plans, service plans, and account plans.
Variable costs
are the costs derived from the pricing rules applied to each method/metric configured in the application plan. They are based on the usage of your API and therefore cannot be known in advance, only when the billing period has concluded. Only available on application plans.

Service and account plans are only available in 3scale SaaS Enterprise plans.

Example

If you have a plan with monthly cost of $10, but want to charge your developer a $5 setup fee. The initial charge would be for $15, while all subsequent charges would be for $10.

13.1. Pricing rules

Pricing rules define the cost of each API request. Multiple pricing rules on the same metric divide up the ranges of when a pricing rule applies. Pricing rules are based on calendar month, and the counter is reset at 00:00 UTC of the 1st day of each month.

Example 1

Until 100 calls per month (from 1 to 100) each API call can be charged at $0.04, and starting from the call 101 (from 101 to infinity) the calls are charged at $0.10.

Example 2

The first 1000 calls are not charged (cost $0), because they are included in the plan which has a monthly fixed cost. Starting from call 1001, each call is charged at $0.50.

Example 3

Calls from 1 to 100 are charged at $0.30, 100 to 500 – at $0.40, and 500 and further – at $0.50.

Note

Pricing rules are defined for metrics and methods. The actual API requests are mapped to these metrics and methods through the Mapping Rules.

13.2. Setting pricing rules

  1. Go to [Your_API_service] > Applications > Application Plans.
  2. Select an existing application plan or create a new one.
  3. In the section Metrics, Methods, Limits & Pricing Rules click Pricing (x) to open the pricing section.
  4. Click new pricing rule.
  5. Set the values From, To and Cost per Unit and click Create pricing rule.

Repeat the last two steps to create all the necessary pricing rules ranges.

Leave the To field empty to set the rule to "to infinity".

The maximum number of decimals is set to 4 for the cost of metric, if a number is added with more decimals, the value is rounded to a number with 4 decimal places.

13.3. Update existing pricing rules

  1. Click on edit.
  2. Make the necessary adjustments to the From, To and Cost per Unit fields.
  3. Click Update pricing rule.

Chapter 14. Billing

The billing process creates invoices under the developer account, if it is subscribed to any paid services. The invoices are charged using the configured payment gateway.

14.1. Listing invoices

In the Audience > Billing > Earning by month section you can find an overview of your due and received payments, calculated as the sum of all invoices issued that month, depending on their state:

Total
all invoices excluding cancelled
In process
Open, Finalized and Pending invoices
Overdue
Failed and Unpaid invoices
Paid
Paid invoices

By clicking on a specific month you can list all invoices for that month.

You can also see the list of invoices by going to Audience > Billing > Invoices, where you can find invoices by their ID (friendly ID), the account name, and also filter by month and state.

The invoices of a specific developer account can also be found under X Invoices in the breadcrumbs of the account details page at Audience > Accounts > Listing > [selected account], where X is the number of invoices the account has.

14.2. Invoice view

If you click on the invoice friendly ID from the invoices list, you will see the details of the invoice.

14.2.1. Invoice details

The title includes the month and year of the invoice, and also shows whether the invoice was created manually or by automated billing process, e.g. Invoice for February 2018 (manually created).

The Details block below shows the friendly ID of the invoice, invoice state, dates when the invoice was finalized and issued, and when it’s due and paid on. If PDF has already been generated, the link to download the PDF will be also shown.

The Issued by and Issued to blocks shows the name and the address of the API provider and the developer account accordingly.

Below a block with line items will be shown, including calculations of the VAT/Sales Tax, total cost, and if the text in "Text to show if VAT/Sales Tax is 0%" was configured, it will also be shown here.

In the Transactions block of the invoice you can see the list of all credit card transactions attempts, including the status of the transaction, its timestamp, reference number, message provided by the payment gateway and the amount. You can find the transactions in your payment gateway administrator console using the reference number.

14.2.2. Editing invoices

If the invoice is in Open or Finalized state, you can edit some details of the invoice.

By clicking on the Edit link at the top right corner of the invoice view, you can change the friendly ID and the billing period.

You can also add and delete invoice line items (except calculated costs – total, VAT/sales tax, total with VAT/sales tax). To add a new line item, click on Add, and fill in Name, Quantity (doesn’t affect the cost), Description and Cost.

The links at the bottom of the invoice view can trigger actions on the invoice – different actions are available depending on the current state of the invoice, e.g. Generate PDF, Issue invoice Cancel invoice, Regenerate PDF, Charge, Mark as paid etc. These actions (except PDF-related) will change the state of the invoice.

14.3. Invoice states

The invoice can be in one of the following states:

Open
the invoice is created, but the automated calculations has not yet been finalized.
Finalized
the invoice has all the current billing period charges added to it.
Pending
the invoice has been issued to the developers and is awaiting payment.
Unpaid
the invoice has been charged unsuccessfully, but pending automatic retry.
Paid
the invoice has been charged successfully.
Failed
the invoice has been charged unsuccessfully, and automatic retry will not be attempted anymore.
Cancelled
has been cancelled by an admin.

14.4. Automated billing process

In 3scale, the billing process runs daily. It generates invoices, changing their states according to the billing flow, and performs charges using the configured payment gateway.

The billing flow is a bit different for Prepaid and Postpaid mode, and as billing in 3scale is based on calendar month, there are special events that happen on the 1st day of the month.

14.4.1. On the 1st day of each month

Postpaid

  • Bill variable cost for the previous month (the cost is included as a line item to the open invoice)
  • Finalize open invoices for the previous month
  • Bill fixed cost for the current month (create a new invoice for current month in Open state)

Prepaid

  • Bill fixed cost (current month)
  • Bill variable cost (previous month)

Notifications are sent to the API admins about the invoices finalized in the beginning of the month, so they can review the invoices and make necessary adjustments.

All actions that are performed every day also happen on the 1st day of the month in addition to the ones described above.

14.4.2. Every day

  • Bill expired trials and new contracts that haven’t yet been billed (invoices in Open state for the current month are created).
  • Prepaid only: Finalize all open invoices (state changes to Finalized).
  • Issue invoices (state changes to Pending).

    • The invoices are normally issued 2-3 days after they were finalized. The "Issued On" date of the invoice is set to current date, and the "Due On" date (when the invoice will be charged) is set to the Issued On + 2 days.
    • When the invoice is issued to the developers, they receive an email notification, and can see the issued invoice in the developer portal.
  • Charge invoices

    • The invoices in Unpaid and Pending states are charged, if the Due On date is today or earlier.
    • If the payment failed, the invoice state is changed to Unpaid. Charging will be retried again in 3 days. After 3 unsuccessful retries, the invoice state is changed to Failed, and charging is not retried anymore.
  • Notify about expired credit cards

    • the developer accounts whose credit cards are going to expire soon are sent email notifications.

14.4.3. Automatic and manual invoices

The invoices that are generated by the automated billing process have "(automatically created)" label in the invoice header (e.g. "Invoice for January 2019 (automatically created)").

The invoices that are generated manually are marked with "(manually created)" on the invoice details page.

The automated billing process may use existing invoices in "open" state for the current month to create additional line items, but only for automatically created invoices. The invoices created manually will not be updated by the automated billing process.

14.4.4. Mid-month upgrades

If an application (or account/service subscription) is upgraded in the middle of the month, the monthly cost is prorated according to the number of days left in the month. The limits configured on the application plan are not prorated.

If the application is upgraded from a free to a paid plan, the next time billing runs a new invoice will be generated including the prorated monthly cost.

When the application is upgraded from a paid plan to a more expensive paid plan, the behavior depends on several factors:

  • the mode of Billing: Prepaid or Postpaid
  • when the plan change is made

14.4.4.1. Prepaid billing

  1. If the application plan is changed on the same billing day (a billing day starts at 8am UTC) as is it was created, and so it has never been invoiced before, the fixed costs for the old plan are included to the invoice, and are discounted with a 'Refund' line item. The fixed costs for the old plan are also added to the invoice.

    Example: A customer signed up for the Plan A (200$) on the first day of the month, and upgraded to the Plan B (300$) on the same day. One invoice will be generated in this case, and it will contain the following line items:

    DescriptionCost

    Fixed fee ('Plan A')

    200

    Refund ('Plan A')

    -200

    Application upgrade ('Plan A' to 'Plan B')

    300

    Total

    300

    Note that if the customer signed up on another day of the month, the cost of and refund of 200 would be prorated.

  2. If the application plan is changed after the invoice was already issued for this application:

    • In case of an upgrade, the developer will be issued two invoices: one for the initial charge, and another one for the upgrade.

      Example: A customer signed up for the Plan A (200$) on the first day of the month, and then upgraded to the Plan B (300$) in the middle of the month. The following invoices will be generated:

      DescriptionCost

      Fixed fee ('Plan A')

      200

      Total

      200

      DescriptionCost

      Refund ('Plan A')

      -100

      Application upgrade ('Plan A' to 'Plan B')

      150

      Total

      50

      In the second invoice, the refunded cost (100$) and the new cost (150$) are prorated, as the upgrade is made in the middle of the billing period.

    • Refunding on application downgrade (change to a plan with a lower cost) is not supported at the moment.

14.4.4.2. Postpaid billing

In Postpaid billing mode a single invoice will be issued, and it will include the 'Refund' and 'Application upgrade' line items.

IMPORTANT: This behavior was introduced on April 20th, 2018 with the following changes:

  • A bug was fixed where the initial charge (for the initial application plan) was not included in the invoice when the application was upgraded on the same day as created.
  • Previously only one line item was added on application upgrade, including the difference between the cost of the new and the old plan. For example, in the scenario 2 described in Prepaid billing section above (application upgrades from Plan A – 200$, to Plan B – 300$), the second generated invoice would be:
DescriptionCost

Application upgrade ('Plan A' to 'Plan B')

50

Total

50

where 50$ is the difference between the prorated costs of the new and old plan for the rest of the month (150$ - 100$).

After April 20th, 2018, the calculations are reflected more clearly in the invoice (including refund and charge separately), while the total cost remains the same as before.

14.5. Enable/disable billing/charging per account

Automated billing process generates invoices for all developer accounts subscribed to paid services.

Charging can be enabled or disabled globally (see Billing and Charging settings ), however it is also possible to enable or disable both billing and charging per developer account. To do that, navigate to the account page and click the corresponding button (Enable / Disable) against:

  • Monthly billing is enabled/disabled
  • Monthly charging is enabled/disabled

If charging is disabled, and billing is enabled, the developer will be issued invoices, but will not be charged. This is useful in case you handle charging separately (e.g. with wire transfer).

If both are disabled, the developer will not be issued or charged.

If billing is disabled, and charging is enabled, the developer will not be issued any new invoices, but all the outstanding ones (Pending and Failed) will still be charged.

Here in the Billing Status block you can also see whether the credit card details are configured on the account. In case credit card details are configured, the month and the year of card expiration is shown. The presence of the credit card details may affect the developer portal flow on sign up and plan change (see more in Section 14.9, “Credit card flow”).

14.6. Plans with Trial Period

A trial period (in days) can be set for paid plans to delay the charging for the specified amount of days.

The trial period status will be shown for the application in the application listing ([Your_API_service] > Applications > Listing) in the State column as "live – trial expires in N days", and in the application details page in the Trial days left field.

During the trial period the application can use all the features and usage limits defined by the plan without restrictions.

Once the trial period is set, it is not possible to cancel or extend it. Upgrading to another plan will not reset the trial days counter.

10 days before the trial period expires, an email notification is sent to the developer account notifying about the upcoming trial expiration. The template of this email can be configured in Audience > Messages > Email Templates: "Application trial period expired for buyer" for the application plans, and "Service trial period expired for buyer" for service plans with trial period. The developer should either remain on the current plan, or switch to another plan, or contact the API provider if they decide to cancel the subscription.

Once the trial period is over, the next time automated billing runs (see Section 14.4, “Automated billing process”) the developer will be charged according to the costs set for the plan that the application or service are currently on. Note that the application will not be blocked or suspended after the trial period expires, and will continue to work.

Note that while a trial period technically can be set for free plans, it is not recommended as the feature loses its usefulness.

14.7. VAT rate/Sales Tax

Value-Added Tax (VAT) is a tax that is applied on goods and services sold within European Union. In other countries there is a similar tax, for example, Sales tax. API providers who charge their customers for using their API service often need to charge the tax as well and reflect it in the invoices to comply with the existing regulations.

3scale billing can automatically include VAT in the invoices, when configured.

14.7.1. Configure VAT rate field

VAT rate is the number (in percentage) that will be applied to the total cost in the invoice. To configure VAT rate, follow these steps in the Admin Portal, from the Dashboard:

  1. Go to Audience > Accounts > Fields Definitions.
  2. Click Create in the Account section.
  3. Select vat_rate in the [new field] drop-down list.
  4. Set a value for Label.
  5. Configure the checkboxes to indicate whether the field should be Required, Read only or Hidden for the developers.

    NOTE: the "Choices" field only accepts strings, so this field cannot be used.

  6. Click Create.

14.7.2. Configure VAT code field

VAT code is the VAT identification number. To configure the VAT code follow these steps in the Admin Portal, from the Dashboard:

  1. Go to Audience > Accounts > Fields Definitions.
  2. Click Create in the Account section.
  3. Select vat_code in the [new field] drop-down list.
  4. Set a value for Label.
  5. Configure the checkboxes to indicate whether the field should be Required, Read only or Hidden for the developers.
  6. Click Create.

14.7.3. Set VAT values for an account

Once VAT code and VAT rate fields are added, you can set the corresponding values under the developer account Edit form. Depending on the selected checkboxes in the fields definitions the fields can also be visible and/or editable by the developers in the developer portal.

VAT code can be any string.

VAT rate must be a number. Either integer or decimal numbers are accepted (e.g.: 21, 23.5 etc.) and they represent the percentage of the cost that will be included as VAT.

14.7.4. Invoices with VAT

When an invoice is generated for a developer account that has a non-zero VAT rate configured, the invoices will include the following line items:

_Total cost (without <VAT rate>)_ +
_<VAT rate> Amount_ +
_Total cost (<VAT rate> <VAT rate value>% included)_

<VAT rate> will be replaced with the Label set for the VAT rate field, and <VAT rate value> is the value configured for the account the invoice is issued for.

The VAT code will be included in the PDF version of the invoice with the label, specified in as the Label in the VAT code field definition. The value will correspond to the value set in the developer account details.

The fields vat_rate and vat_code can also be read and written by the 3scale Account Management API.

14.8. Developer portal view

The developers can manage their Credit Card information and see their invoices in the developer portal.

The Finance switch in Audience > Developer Portal > Feature Visibility has to be in Visible state for the developers to see the billing-related elements in the developer portal.

A logged-in user can update the credit card details at Settings > Credit Card Details. Depending on the payment gateway configured the form may be different, and the user may need to enter the billing address first.

*Note:* Credit card details are not stored in the 3scale API Management database, it is managed by the payment gateway. Only the last 4 digits of the credit card number, the expiration date and the reference provided by the payment gateway are stored in the 3scale API Management database.

A developer can only have one credit card card on the developer portal.

Credit card details cannot be deleted from the developer portal. The user of the developer account who wants to delete his credit card details would need to request the API provider to delete the credit card details from the system.

To see the invoices, the user can go to Settings > Invoices, and from there they can either show the details for each invoice, or download the invoice PDF.

14.9. Credit card flow

14.9.1. Sign up for a paid plan

When a developer signs up for a paid plan, they are requested to enter the credit card details before they are allowed to see the application credentials. Once the developer logs in to the developer portal for the first time, they will be redirected to the Credit Card Details page. Trying to access any other developer account page will result in a redirection to the Credit Card Details page again.

If the 3scale account was created before July 5th, 2016, this behavior needs to be enabled manually by setting the switch Credit Card on Signup in Audience > Developer Portal > Feature Visibility. Otherwise, the application credentials will be visible even when the credit card details are not set.

If you prefer, you can hide all the menu items except the Credit Card Details tab by customizing the corresponding developer portal templates with help of the Liquid tags.

The current_account Liquid drop exposes the method requires_credit_card_now? which returns true if the credit card details are missing, but are required (only if Billing is configured in the Admin Portal), and false otherwise.

You can hide any menu items and other UI elements in the submenu and users_menu partials by wrapping them with the following condition:

{% unless current_account.requires_credit_card_now? %}
...
{%  endunless %}

14.9.2. Upgrade from a free to a paid plan

For plan changes of the existing applications there are multiple options that can be configured, including changing the plan directly by the developer or requesting a plan change. In case the application is upgraded from a free to a paid plan, it is important to ensure that the developer enters the credit card details before being able to upgrade. This can be configured in [your_API_name] > Integration > Settings, Application Plan Changing section by the following setting:

Change plan directly if developer has credit card, otherwise:
- Only request a plan change
- Request Credit Card entry for paid plans

Select the first option if you want to only allow the developer to request the change, and perform the upgrade manually after the credit card details are entered.

Select the second option if you want the developer to be notified that credit card details need to be entered before upgrading to a paid plan. In the plan selector widget the developer will see a message "You cannot change plan until you enter your Credit Card details" pointing to the credit card details form.

14.10. "Billing address" field

When the developer enters the billing address on the Credit Card Details in the Developer Portal, this address is stored separately from the "legal" account address.

By default the legal address appears in the Invoices in the Issued to field. However, in case the developer does not have the legal address configured, but only the billing address, the latter will be used on the invoices (Note: the organization name is considered part of the address in this case).

By default the billing address is not visible in the Admin Portal or through the API, however you can add it as follows:

  1. Go to Audience > Accounts > Fields Definitions.
  2. Under the Account block click Create.
  3. Select 'billing_address' from the drop-down list, add the label, check the Read only checkbox and click Create.

Now the <billing_address> field appears in the XML model for Accounts in the Account Management API and Webhooks. The corresponding billing address will be visible as read-only in the Account and the Account edit pages of the Admin Portal.

Billing address can be changed by the developer in the Developer Portal (in the Credit Card Details section). The admin cannot change the billing address in the Admin Portal, but it is possible to do so with the Account Edit endpoint of the Account Management API using the following fields (as "additional fields"):

billing_address_name
billing_address_address1
billing_address_address2
billing_address_country
billing_address_city
billing_address_state
billing_address_zip
billing_address_phone

Chapter 15. Email Notifications

Different events related to billing trigger email notifications for API providers and developers.

15.1. Provider notifications

The users of the 3scale account (admins and members with Billing permission) can subscribe to or unsubscribe from the notifications related to billing at Account Settings (gear icon on the top-right) > Personal > Notification Preferences, under Billing section:

Action required: review invoices
Sent a few days before end of billing cycle so you can review invoices before they are being sent to customers.
Customer downgraded
Sent when a customer changes to a plan with a lower monthly fixed price.
Expiring credit card
Sent when a customer’s credit card is about to expire.
Payment error (retry)
Sent when payment fails, resulting in an unpaid invoice and a retry.
Payment error (final)
Sent when the final retry of a payment fails, resulting in a failed invoice.

Note: All admin users of the 3scale account will receive notifications regarding billing, if they are subscribed to them.

15.2. Developer emails

The email notifications sent to the developer accounts can be configured at Audience > Messages > Email Templates. The following emails are available:

Credit card expired notification for buyer
Sent when the credit card is due to expire soon.
Invoice charged successfully for buyer
Sent when the invoice has been successfully charged.
Invoice charge failure for buyer with retry
Sent when the invoice charge has failed, and the invoice is in Failed state, which means that the charging will be retried again.
Invoice charge failure for buyer without retry
Invoice charge has failed for the 3rd time, the invoice has passed to Unpaid state and will not be retried again.
Upcoming invoice charge for buyer
Sent when the invoice is issued for the developer.

All admin users of the developer account will receive the above notifications.

15.2.1. Billing email address

You can configure an email address that your customers can contact for resolving any issues with billing (e.g. billing@example.com), in Audience > Messages > Support Emails in the Finance support email field.

The email templates reference the email address with the Liquid drop {{ provider.finance_support_email }}.

Chapter 16. Billing API

The Billing API provides a way to automate common billing processes.

All the endpoints of the Billing API can be found in the Admin Portal under Documentation (?) > 3scale API Docs > Billing API.

The Billing API requires a valid access token which meets the following requirements:

  • it should belong to either an admin user of the provider account, or a member user with "Billing" permissions
  • it should include "Billing API" scope

Note that when an invoice ID is required as a parameter, it refers to the invoice ID, and not the Friendly invoice ID.

The XML response of the API endpoints is mostly self-explanatory, and the fields of the Invoice represent the same information as in the web and PDF representation.

Some notable fields of the response:

  • creation_type: can have the following values: 'manual' for invoices created manually or 'background' for invoices created by the 3scale automated billing process
  • provider: the details of the API provider (the admin account), corresponds to the Issued by section of the invoice.
  • buyer: the details of the developer account, corresponds to the Issued to section of the invoice.

The XML representation of the invoice also includes the list of Line Items under the line-items field.

For some line items (typically the ones created automatically) apart from the expected name, description, quantity and cost (price), you can see the following:

  • type: the type of the line item, can have the following values:

    • LineItem::PlanCost – for line items for fixed plan costs
    • LineItem::VariableCost – for line items for variable costs
  • metric_id: for variable costs line items – the ID of the metric that the cost is associated with
  • contract_id: the ID of the service or application that the cost is associated with

Chapter 17. Ogone Integration

Warning

Ogone integration is deprecated. New integrations are not supported. For integrations existing before 27th of July 2018, Red Hat provides support, but recommends to migrate to one of the fully supported payment gateways: Stripe, Braintree or Adyen.

These are the steps to set up the Ogone gateway in order to to charge for use of your API.

17.1. Step 1: Get your API keys from Ogone

You’ll need to open an account with Ogone. You need a premium Ogone ecommerce account – the Horizon activated with Alias Manager option. It’s a paid option, which can be activated by Ogone or by Merchant through backoffice > options > your options.

The PSPID is used to log into your Ogone account. Then you can find the UserID under Configuration > Users.

Billing Ogone ids

Make sure that the technical settings of your Ogone account are active. On the Transaction Feedback page, you’ll find the SHA-OUT passphrase. On this page you should also ensure that the two settings have checkboxes marked as shown:

Billing Ogone SHA-out

Finally the SHA-IN passphrase is found on the Date and origin verification page:

Billing Ogone SHA-in

17.2. Step 2: Configure your settings in 3scale

You need to tell 3scale to start using these API keys. To do this, log in to your 3scale Admin Portal and go to Settings > Billing.

Billing

If the Charging Enabled flag is not active, enable it and click Save.

Billing charging enabled

You should see a drop-down called Gateway near the bottom of the page. Change it to Ogone.

Billing Gateway

The form below the drop-down should change to show two fields. Insert your Ogone API keys and click Save.

Ogone billing gateway

You might see a couple of alerts when you change your payment gateway. This is expected. Read and accept them if they appear.

The payment gateway is now set up, but your users might not be able to use it yet since it’s not configured in the CMS. Go to the Developer Portal page and click on the template called Payment Gateway / Show on the left navigation pane.

Developer Portal - Billing

If it’s not there already, add the following code before {% when "braintree_blue" %}:

{% when "ogone" %}
  {% if current_account.has_billing_address? %}
    {% if current_account.credit_card_stored? %}
      {% ogone_form "Edit Credit Card Details" %}
    {% else %}
      {% ogone_form "Add Credit Card Details" %}
    {% endif %}
  {% else %}
    <p><a href="{{ current_account.edit_ogone_billing_address_url }}">First add a billing address</a></p>
  {% endif %}

Finally click Save and Publish. Your users should now be able to pay using the Ogone gateway.

17.2.1. Note

In order to map your data from Ogone with your data on 3scale, you can use the Ogone field called alias which is composed of 3scale-[PROVIDER_ID]-[DEVELOPER_ACCOUNT_ID]

17.2.2. Troubleshooting

In case something is not working, you can try checking the following tips:

  • An overview of all payment methods that work with the alias manager can be found in this document: Payment methods processing/procedure overview.
  • In the Ogone admin console go to Technical information → Transaction feedback. Scroll to Directlink/Dynamic Parameters and select all parameters. This will allow you to troubleshoot the error easier (as the error message will be included in the invoice).
  • Try to change your ogone password and update this setting in the 3scale console
  • Verify if your user was created in your Ogone account with the checkbox "Special user for API (no access to the admin)" checked. You can also search the Ogone Support FAQ for "API user" for the details.
  • Make sure that you are entering in 3scale the password of the "API user", and not the password of Ogone PSPID-account
  • In case you are using the sandbox mode in Ogone and encounter any errors, change it to production.

Chapter 18. Authorize.Net Integration

Warning

Authorize.Net integration is deprecated. New integrations are not supported. For integrations existing before 27th of July 2018, Red Hat provides support, but recommends to migrate to one of the fully supported payment gateways: Stripe, Braintree or Adyen.

Integrate the Authorize.Net payment gateway with the Red Hat 3scale billing system.

Prerequisites:

  • A valid Authorize.Net account
  • The following Authorize.Net credentials

    • API login ID
    • Transaction key

Configure 3scale API Management:

  1. Log in to your 3scale admin portal.
  2. Navigate to the SettingsBilling page.
  3. Under the Basics section, select Authorize.Net from the dropdown menu.
  4. Under the Authorize.Net Options section, enter your Authorize.Net API login ID and transaction key.
  5. Select the Save Changes button.

Part IV. Managing developer accounts

Chapter 19. Adding developers

These are the steps to add a new developer account for access to your API.

If you have configured the workflow to invite developers manually, this covers how to add new developers.

19.1. Create a new developer account

  1. Follow Accounts link from the Audience section on the Admin Portal.
  2. Click Create.

As an admin, you can skip even some of the required fields. If you want to invite users to the account securely, you can also skip the password fields. However the email on this main admin account must be unique among all users.

Create new developer account

19.2. Set up applications

If you want to pre-configure app keys for the account, you can also add an application on behalf of the developer. Otherwise, leave this as one of the initial steps for the developer to take.

Add applications to new account

19.3. Notify the developer

You can either send an email invitation to the developer manually or follow the steps to use the invite developer feature.

Chapter 20. Approving developers

This section shows how to make approvals for any step in the signup workflow.

Once you’ve implemented the signup workflow with manual approval steps, you have a few options. The approval process is slightly different depending on the trigger and what is being approved. If you receive an email notification, follow the instructions in the following section. Otherwise, it depends on whether you want to approve an account, a service, or an application.

20.1. Approve from email notification

If you (as admin) receive an email notification that one of your developers has an item pending approval, you can copy/paste the URL for the item into your browser, and it will take you directly to the page to make the approval.

20.2. Account approval

To search for specific accounts or filter all accounts that are in a “pending” (for approval) state, navigate to Audience > Accounts > Listing. To show only the pending accounts, select "Pending" in the dropdown list State and click Search.

You can make individual approvals directly on each row, or select several rows at a time and perform a bulk approval.

Developer approval account signup

20.3. Service approval

To search for specific subscriptions to a service or filter all subscriptions that are in a “pending” (for approval) state, navigate to Audience > Accounts > Subscriptions.

To view Subscriptions, enable Service Plans in Audience > Accounts > Usage Rules.

You can select one subscription or several at a time and perform a bulk approval.

Developer approval service subscription

20.4. Application approval

To search for applications or filter all applications that are in a “pending” (for approval) state:

  1. Navigate to Audience > Applications > Listing.
  2. Select "pending" in the dropdown list State and click Search.

You can select one application or several at a time and perform a bulk approval.

Developer bulk approvals apps

You can also start from the details page for a developer account, select which application you wish to approve from there, and make the approval on the application details page.

Developer individual app approval 1
Developer individual app approval 2

Chapter 21. Changing plans for an app

After this section you will be able to change plans for accounts, services or applications.

As admin you may change plans for a developer at any time, or in response to a plan change request that the developer initiates.

Note

The change plans step is slightly different depending on what type of plans are being changed.

21.1. Change account plans

To search or filter specific accounts, navigate to Audience > Accounts > Listing.

You can select one or more rows at a time, and change the plans.

developer change account plans

21.2. Change service plans

To search or filter specific subscriptions to a service, navigate to Audience > Accounts > Subscriptions.

You can only view subscriptions if you have enabled Service Plans in the Settings page.

You can select one or several subscriptions at a time, and change the plans.

Change service plan

21.3. Change application plans

To search or filter specific applications, navigate to Audience > Applications > Listing.

You can select one or several applications at a time, and change plans.

Change plans for multiple applications

Another scenario is to start from the details page for a developer Account. From there you select the application for which you wish to change plan. On the application details page, you can change the plan.

Change application plan

21.3.1. More information

If rather than change to another standard plan, you only want to make a change for one specific app, you can use the customize plans feature.

Chapter 22. Contacting developers

This guide explains how to find out which developer account manages a particular application and then communicate with them – both through 3scale and externally.

During API operations, you may urgently need to contact developers who are using your API.

22.1. Locate the relevant application and account in the system

If you already know the account and developer who manages the application in question, navigate to their account from the Accounts page in Audience > Accounts > Listing, as shown below.

Accounts View

If you only have the application ID or API key, you can use the search box on the Accounts page in Audience > Accounts > Listing to find the relevant account. More information on locating applications is available here.

22.2. Send internal messages to developers

Once you are in the account profile page as shown below, click the message icon.

Send message

The message created here will be sent both to the account system dashboard, where all developers on the account will see it, and by email to the people on the developer account who have admin status within the account.

22.3. Contact by other means

If it’s an emergency and email is unlikely to be fast enough for your purposes, you can also use the contact information submitted by the developer at time of signup, which is available:

  • On the company account page (general contact information but may include a phone number)
  • Developer/user specific information on the users’ own file

Note that you can make contact phone numbers a required field upon signup.

Chapter 23. Customize plans

When you have completed this section you will have customized an application plan for a specific developer.

Application plans are a good way to apply standard policies for different segments of your developer community. However, you always have the flexibility to customize the standard plans for any individual developer with unique requirements.

Once a plan is customized, you lose the link to the original plan. If you make changes to the original plan, the custom plan does not inherit any of those changes. So you should use this customization feature sparingly, before you become overwhelmed with too many custom plans which you cannot manage effectively.

A developer wants to increase their current limits without upgrading to the next pricing tier as the current billing period is already under way. A customization could be a good way to handle this situation by enabling the increase in limits and charging only the variable costs incurred. This would also help encourage an upgrade for the following billing month.

23.1. Choose the account

To view the details page for the developer Account you are interested in:

  1. Navigate to Audience > Accounts > Listing
  2. Choose the Developer account
Select Account

23.2. Select the application

Select the application whose plan you wish to customize.

Select App

23.3. Customize the application plan

Select the option to “customize”. This provides the page where all the plan elements can be customized for the application owned by this account.

Customize Plans

23.3.1. More information

Before you take the step to customize plans, always consider first if you are not better off with a new standard plan (which can be hidden from display in the Developer Portal). Then you would just change to the standard plan and so gain the benefit of reuse if this applies to more than one of your developer partners.

Chapter 24. Enable signup

Configure developer signup by implementing self-service or manual mode.

You can configure the workflow for developers to be self-service or by manual invite only. Self-service signups are done by developers through the Developer Portal, while manual invites are handled by your admins through the Admin Portal.

By default, the checkbox toggle is set to enabled. To do so, navigate to Audience > Accounts > Settings > Usage Rules.

Enable self-service developer signup

Chapter 25. Finding applications

By the end of this guide, you’ll be able to quickly locate an application in the Admin Portal based on either its name, an API key, or an application identifier.

During API operations, you may need to be able to find information on an application that is accessing your API quickly – either for support purposes, to change configuration, or potentially because the application is misbehaving and needs to be disabled.

25.1. Get the information you need

To find an application, you need the name of the account it belongs to or the application’s name. If you do not have this information, you can verify the access logs. To perform the search, navigate to Applications (Audience > Applications > Listing).

If you search by identifier for an authentication type, you need the following information:

  • For API key-only authentication patterns: the API key
  • For app ID and app key authentication patterns: the app identifier (search by app key is not supported)
  • For OpenID Connect authentication patterns: the client_id (search on the secret is not supported)

25.2. Search for the application

To search a given application, navigate to Applications page (Audience > Applications > Listing), and use the search box as shown in the image below.

Finding an application part 1

25.3. Access application information

Once the results are returned, click on the application you’d like to access and you’ll be taken to that application’s homepage, which includes information such as that shown in the image below.

Finding an application part 2

Chapter 26. Inviting developers

After completing these steps, you will have added a new developer user to a developer account.

When you create a developer account manually, you can invite developer users to that account through the Admin Portal:

  1. Navigate to Audience > Accounts > Listing.
  2. Choose the account in question.
  3. Select "Invitations" and then click Invite user.
Developer invite user

Chapter 27. Unsubscribing developers from a service

As an admin, you can unsubscribe developers from a service. You may need to do this for one specific developer, or for multiple developers, in the event of a service deprecation.

27.1. Unsubscribing a single developer from services

Unsubscribe a single developer from a service they are subscribed to through the Admin Portal:

  1. In the Admin Portal’s Dashboard, navigate to Audience > Accounts > Listing > [select an account] > Service Subscriptions.
  2. Select Unsubscribe for the service that you want to remove the developer from.

27.2. Unsubscribing multiple developers from services

Perform a bulk action to unsubscribe multiple developers from a deprecated or deleted service:

Note

This method only applies to services that have been deleted or suspended. You cannot perform a bulk unsubscription action on active services.

  1. In the Dashboard, navigate to: Audience > Accounts > Subscriptions.
  2. Do bulk state change.
  3. Using the service dropdown menu, identify the service from which you want to unsubscribe developers.
  4. Using the checkboxes on the left, select the developers you want to unsubscribe.
  5. Select Change State > Suspend to suspend the selected developer subscriptions.

Remember that service plans need to be enabled.

Chapter 28. Suspending applications

This guide explains how to disable all keys and access tokens for an application.

If an application is misusing your API and affecting other traffic, you may need to quickly suspend its operations before contacting the developer involved to ask them to amend their code or configuration.

28.1. Find the application

You can find the application from the Accounts or Applications tabs or by searching as described here.

28.2. Disable the application

Once you have located the application and see the application summary page, click on the suspend icon next to the ‘State’ value. This action will immediately disable the application from the API and suspend all keys from working. Calls with these application keys will be rejected by the control system.

The application can be unsuspended using the same button once the problematic behavior has been rectified.

Suspend an Application
Note

If you use caching in your agents, suspension may not be immediate but require a short timeout.

28.3. Contact the developer

How you contact the developer of the application will depend on your workflow and policy. On the same page, you can click on the account name, which will take you to the account view where you can identify the key administrator of the account that owns the application. You can contact them either by email or by clicking on the send message button as shown, which will generate a dashboard message for the user.

Contact Developer

Chapter 29. Deleting applications

To delete an application via the Admin Portal, you need to follow these steps:

Option 1: Delete an application from the list of all applications for [Your_API_name].

  1. In the Dashboard, click [Your_API_name].
  2. Click the Overview tab.
  3. From the left panel on the Overview page, click Applications.
  4. Choose Listing.
  5. Click on an application.
  6. You will see a page containing details of the application. Click Edit.
  7. To delete the application, click Delete.
  8. You will see a confirmation message. Click Ok to confirm the deletion.

Option 2: Delete an application based on a specific application plan.

  1. In the Admin Portal, click Dashboard.
  2. Choose API.
  3. Under Published Application Plans, choose an application.
  4. Click on an application.
  5. You will see a page containing details of the application. Click Edit.
  6. To delete the application, click Delete.
  7. You will see a confirmation message. Click Ok to confirm the deletion.

Alternatively, you can also delete an application via 3scale API Docs, with the operation called Application Delete.

Part V. Analytics

Chapter 30. API analytics

This guide is designed to help you tune your API analytics to track the items you need to know about and to see top applications and trends over time.

Knowing how your API is used is a crucial step for managing traffic, provisioning for peaks, and identifying top users so you can help them achieve greater success with your API.

30.1. Prerequisites

Complete the instructions of the Getting Started section before using this guide.

The guide assumes that you are using one of the existing 3scale code plugins to perform an integration. You can follow a similar flow with other integration methods. Check the APIcast Overview chapter of the documentation to learn more about the available integration options.

30.2. Determining the metrics and methods to track

3scale acts as an infinitely scalable data repository for your API statistics, and you can track almost any metric for your API. For example:

  • Hits/transactions: calls to the API. Hits are included by default as metrics on all APIs. Hits can be overall calls to the API or broken out into individual methods on the API.
  • Data transfer: quantity of MB/GB of data uploaded and downloaded via the API
  • CPU hours: compute time (or some other internal resource) associated with calls to the API
  • Results returned: count of the number of records or data objects being returned
  • Disk storage: total disk storage in use by an account

You can track more metrics that are relevant to your API. 3scale can track an arbitrary number of metrics and methods, as long as it is a countable quantity that can be incremented over time.

30.3. Creating your metrics and methods

After you chose your metrics, register them in the 3scale Admin Portal. Navigate to [your_API_name] > Integration > Methods & Metrics.

Figure 30.1. Create new method

Create new method

Add metrics and methods to the service. Provide them with a friendly name and a system name, which is used later in your plugin configuration. For more details about creating methods and metrics, see defining your API on 3scale.

30.4. Setting up reports

Once you have configured the 3scale system with the names of the metrics to track, it is time to tweak your plugin setup to report the right metrics. The precise manner of doing this depends on the plugin or integration method in use. By default, the plugins report the hits (API transactions) metric only.

Generally speaking, you need to follow these steps.

  1. The application should pass the appropriate metric/method names to the plugin as determined by the incoming API call. The metric/method value and the increment required is an argument of authorize and/or report methods the plugin exposes.
  2. You can also report the traffic using the 3scale Service Management API. You can find information about different endpoints in the 3scale APIs ActiveDocs section. 3scale ActiveDocs are available in your Admin Portal under the Documentation → 3scale API Docs section.

When you report traffic for a specific API method, use the method system name in the metric argument. This automatically increments the counter both for the method reported and the hits metric.

30.5. Checking that traffic is reported correctly

Once the API and 3scale connection is established, you can send traffic to the API and watch it register on the API Analytics dashboard. You need an existing developer account and an application with API credentials to be able to perform the steps in this section. Follow these steps to create a developer account and get an application with API credentials.

  1. Open the Getting Started guide.
  2. Navigate to Audience > Applications > Listing to see the list of existing applications.
  3. Select an application by clicking on its name.

    Figure 30.2. Applications

    Applications
  4. Find the API credentials for the selected application. The credentials depend on the selected authentication type and can be a user key (API key), an application ID and application keys, or a client ID and client secret. For more information about the available authentication modes, see the authentication patterns article.

    Figure 30.3. API credentials

    API credentials
  5. Use these keys to make calls to your API in the normal way (for example, from the command line using cURL or from the browser for API endpoints using the GET method). The precise calls to make depend on the structure of the methods on your API. Traffic from these calls appear in the Analytics section for your API.

    Figure 30.4. Analytics usage

    Analytics usage

30.6. Troubleshooting

If traffic does not display on the usage charts in the Analytics section, perform the following checks.

  • Are authorize/report calls responding correctly?

    All plugins call the 3scale Service Management API, which has predetermined response codes. Authorize calls for valid keys should return responses with HTTP code 200. Report calls should respond with code 202.

  • Are there errors in the integration error console?

    The log of integration errors detected by 3scale can be found in [your_API_name] > Analytics > Integration Errors.

    Figure 30.5. Integration errors

    Integration errors
  • Are the correct metric and method names being used?

    The most common reason for failure is that the method and metric names passed in report calls do not correspond to those created in the API settings of your Admin Portal. Check that you are using the correct system names for each metric/method.

30.7. Controlling who sees the analytics

By default, the usage statistics are visible to the API provider through the Admin Portal and to the developers who created applications through the Developer Portal. (Each developer can see only the usage statistics for their own applications.) You have the ability to hide the analytics views from the Developer Portal. See the Developer Portal section to learn more about customizing the Developer Portal.

30.8. Accessing analytics data by API and email reports

Besides the usage graphs in the Analytics section, there are other methods of getting your API’s analytics data.

  • Analytics API

    You can use the 3scale Analytics API. It is a flexible way to extract all the analytics data for your API in either XML or JSON format.

  • Daily and weekly traffic reports (SaaS only)

    These reports provide the aggregated data about your traffic, including information about new subscribers to your API and top applications. To enable these reports in the Account Settings (gear icon) > Personal > Notification Preferences of your Admin Portal, find the weekly aggregate reports and daily aggregate reports check boxes. If enabled, these reports are emailed to the admin user of your 3scale account.

  • CSV export (SaaS only)

    There is a download CSV link on each analytics view page, and you can download the usage statistics in .csv format.

    Download CSV image::guides-api-analytics-download-csv.png[width=100px]

Chapter 31. Exporting analytics

This article shows how to create scripts that extend the current capabilities of the built-in 3scale analytics.

By using the Account Management and Analytics API (Enterprise only), you can create scripts that get the custom information that you need in the format that you prefer. This article describes a particular use case, but the same approach can be used to get whatever data you need out of 3scale.

31.1. Reasons for customized scripts

3scale continuously improves the features available on your API Dashboard. However, you may be ahead of our development plans and have a very specific need that’s not yet supported.

To satisfy the needs for API management, 3scale always gives you the tools to access all your data. However, customized scripts have some costs – it takes some resources to write the scripts – but the cost is not too high, as we will show in this article. More importantly, DIY gives you total flexibility and control to implement any use case you can think of.

31.2. A real-world example

Recently a customer came to us with a very specific need that could not be solved with 3scale in a streamlined way.

They were onboarding thousands of new developers per week. They were able to survive such success thanks to the 3scale API Management Platform. Onboarding so many developers would be a daunting task – luckily 3scale provides automates necessities such as key provisioning, sign-up workflows, and email communication. So far so good.

There was, however, something that was not possible to do with 3scale, which was quite important for them. Since they are onboarding so many people, they needed a straight-forward way to classify the new developers based on their engagement with their API so that their operations and marketing teams could interact with the new developers more effectively.

Such a feature, at least at the required level of detail, is not yet available in 3scale’s built-in analytics tools. However since all the data is already available, it can be extracted using 3scale’s Account and Analytics API.

31.3. Example: Customer requirements

They would like to know how many new developers have signed up for the free evaluation plan in the last 10 days, split up different ways.

First, they wanted to know how many developers signed up but didn’t ever use their API. What they wanted to do with this information is out of scope for this article, but it’s clearly valuable information that would help adoption of your API.

Second, they wanted to split the developers that had used their API into two groups:

  • Developers that used it for a period of time – say the first half of the 10 days – and then stopped using the API. These developers tried it out, but became inactive.
  • Developers that have been using the API consistently. For those, they would like to know the percent growth (or decline).

This information is available on 3scale’s built-in analytics. The problem is that there is no view to show it aggregated, which makes the whole experience quite cumbersome.

A typical answer to this problem would be this classification will be part of the upcoming analytics revamp. (Funny thing is that’s actually the case.) But that does not solve the problem if you need it now. We at 3scale want to give you the tools to do everything you need to do without depending on our release schedule.

31.4. Hands-on implementation

31.4.1. Winning recipe

This recipe usually gives better results in achieving custom work.

  • Tinker a bit with ActiveDocs. 3scale ActiveDocs, available in your Admin Portal, under the Account Settings (Gear icon in the top right corner) > Integrate > 3scale API Docs. 3scale has all of its APIs available as ActiveDocs so that you can try them out from your browser. This allows you to find the request that best serves your needs, get the request (curl-like) and get a grasp of the response. See an example…​

    DIY Analytics

This is the ActiveDocs for the API request to fetch all applications that will be used on the script to extend the analytics.

  • Once you’ve done the research with the ActiveDocs, put down the request on your scripting language of choice (ours is pedestrian Ruby). Thanks to the request and responses provided by ActiveDocs, it has never been easier to explore what the API does.
  • Repeat until you have a script that does exactly what you need. For the example of the extended analytics, the script is available as a gist. You can try it out in your account.

As pedestrian as it sounds, this is the easiest way to proceed. The ActiveDocs let you quickly get a grasp of what the API is able to do. Then, it’s just a matter of finding which 3 or 4 requests are needed for the task you want to do and putting a script together.

31.4.2. Step-by-step guide

These were the steps taken to achieve the custom analytics that this customer wanted:

  • Retrieve the full list of applications. This operation requires pagination, but as you can see, it’s dead simple.
def api_call_applications_list(domain, provider_key)
  done = false
  res = Array.new
  page = 1

      while !done
    url = "https://#{domain}/admin/api/applications.xml?provider_key=#{provider_key}&page=#{page}&per_page=100"
    page += 1
    response = RestClient.get url
    raise Exception.new("Wrong response code (#{response.code}) in request #{url}") if response.code!=200
    document = Nokogiri::XML(response.to_str)    done = document.xpath("applications/@current_page").text == document.xpath("applications/@total_pages").text
    document.xpath("//application").each do |item|
      app = Hash.new
      app["created_at"] = DateTime.parse(item.xpath("created_at").text)
      app["plan_name"] = item.xpath("plan/name").text
      app["service_id"] = item.xpath("plan/service_id").text
      app["account_id"] = item.xpath("user_account_id").text
      app["id"] = item.xpath("id").text
      res << app
    end
  end
  return res
end
  • Filter the applications that do not meet the criteria, i.e. the plan must be "evaluation" and they have to be newer than 10 days.
def filter_applications(domain, provider_key, plan_name, num_of_days)
  res = api_call_applications_list(domain, provider_key)
  res.each do |item|
    res.delete(item) if item["plan_name"] != plan_name
    res.delete(item) if item["created_at"] > (DateTime.now - num_of_days)
  end
  return res
end
  • Then for each application that meets the criteria, get its usage, meaning how many hits the application has had in the last 10 days.
def api_call_application_usage(domain, provider_key, application_id, metric, from, to, granularity)
  url = "https://#{domain}/stats/applications/#{application_id}/usage.xml?provider_key=#{provider_key}&metric_name=#{metric}&since=#{from}&until=#{to}&granularity=#{granularity}"
  response = RestClient.get url
  raise Exception.new("Wrong response code (#{response.code}) in request #{url}") if response.code!=200
  document = Nokogiri::XML(response.to_str)
  return document.xpath("//usage/data/values").text.split(",")
end
  • Finally, you must cross-reference the applications to the accounts because the information of the developers is stored in the account object.
def api_call_account_read(domain, provider_key, account_id)
  url = "https://#{domain}/admin/api/accounts/#{account_id}.xml?provider_key=#{provider_key}"
  response = RestClient.get url
  raise Exception.new("Wrong response code (#{response.code}) in request #{url}") if response.code!=200
  document = Nokogiri::XML(response.to_str)
  account = Hash.new
  account["email"] = document.xpath("//users/user/email").text
  account["name"] = document.xpath("//users/user/first_name").text + " " + document.xpath("//users/user/last_name").text
  return account
end

And that’s pretty much it. Now you only need to put everything together (you can get the full script as a gist) and you’re done. You have a script that gets the information that was not yet available on 3scale’s built-in analytics.

31.5. Conclusions

3scale is very DIY-friendly. We believe that anyone should be able to extend the current capabilities of any service that they’ve contracted. As much as we would like to think that we can cover all the bases, we will always be a bit behind in certain aspects, whether because it’s a super special need or simply because we are busy building other features. Whatever the case, we want to avoid blocking you when something is not possible right away. We give you full access to your data and a complete API toolset to work with it.

If you have scripts that you want to share with us and the rest of 3scale’s users, please send them to us. We would be happy to collect them and publish them.

Chapter 32. Out-of-the-box analytics

By the end of this tutorial, you will be able to find visual information on an application’s traffic.

Each application using an API has a traffic trace in the 3scale system, which can be viewed from the Admin Portal as well as recovered by an API.

32.1. Find the application

You can find the application from Audience > Accounts > Listing or Audience > Applications > Listing, or by searching as described in the finding applications tutorial.

32.2. Understand the application display

Once you’ve located the application, you’ll see an overview screen with information about the application as shown in the following image.

Application display

The items labeled in the diagram correspond to the following information:

  1. The name of the application given by the developer.
  2. Meta data captured for the application (learn how to set which data to capture in the advanced section).
  3. The status of the application – is it live or suspended?
  4. The current API identifiers, keys, and certificates that the application has. (This view varies depending on what authentication method was used to integrate the API into 3scale).
  5. A summary of traffic statistics for the application.
  6. Information on which application plan the application is on and which rate limits apply.

32.3. Use the menu to access the full screen statistics view

To get to the Analytics page of an application, go to the application and click on Analytics in the links located above the application’s name. This will take you to the usage charts view for the application as shown in the image below.

Analytics - Time range

Controlling the metrics, methods, and time range allows you to check different types of data about the application.

Chapter 33. Response code tracking

This tutorial shows how to set up and use the response codes log in the 3scale system.

Tracking response codes from your API is a great way to see how your clients are using it and to see in real time whether everything is fine with your servers.

To enable response code tracking feature, set the APICAST_RESPONSE_CODES environment variable to 1 or true when starting APIcast gateway using Docker or OpenShift deployment.

When enabled, APIcast gateway captures the HTTP status code of API responses returned by the upstream service for authorized calls, and sends them to the Service Management API (in authrep call). Example:

https://su1.3scale.net/transactions/authrep.xml?service_token={SERVICE_TOKEN}&service_id={SERVICE_ID}&user_key={USER_KEY}&usage%5Bhits%5D=1&log%5Bcode%5D=200"

In this example,log[code]=200 is sent, which means that the API responded with a 200 status code.

To verify the integration, you must call your API with valid 3scale credentials, and then verify that the call was correctly reported on the Analytics > Usage page.

Usage screen

If everything is going well so far, go to the Analytics >Response codes page. You should be able to see a graph with your latest traffic divided by colors, depending if the response was 2xx, 4xx, or 5xx.

response codes screen

The graph tool gives you the ability to view the history of response codes. You can also check the response code statistics for different periods of time and different levels of granularity. Simply click on the time selection bar and define the time period and granularity that will fit your needs.

Legal Notice

Copyright © 2019 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.