Test your app with one or more APIs using the Test Client testing tool.
The platform provides a Test Client tool that you can use to try out different APIs. The Test Client is a web-based REST client, and is accessible in the context of either an App or an API.
To test your app with Test Client: Choose the app, go to the App Details page, and then, on the left menu, choose Test Client. From the drop-down list, choose an API that your app is connected to. If the API supports anonymous testing, you can also test it without specifying an app at all.
To test an API with one or more of your apps: Choose the API, go to the API Details page, and then, on the left menu, choose Test Client. From the drop-down list, choose one of your apps.
For more information, see What is the Test Client?
When you submit an API access request for an API's sandbox environment, and your request is approved, you can test your app using the sandbox endpoint.
In many cases, though not all, access to the Sandbox endpoint is granted automatically, so you don't have to wait for approval. If you're not sure whether the contract is approved yet, go to your App Details page and, on the left, click APIs. You'll see the status of your contract; most likely, either Pending or Approved.
Once you have access to the sandbox endpoint, you can test your app with the API. For example, you might want to:
By using a testing environment, you can experiment with different scenarios and make adjustments as needed to make sure that your app works as expected with the API.
You can use the platform's built-in Test Client testing tool. See What is the Test Client? below.
If the API supports monitoring, you can view your transaction traffic via monitoring charts and logs. For more information on performance monitoring, see How do I monitor app performance?
Examples of test clients you can use to send REST requests include: Google rest-client, RESTClient Firefox Add-on, and soapUI.
You can also use the platform's built-in Test Client testing tool. See What is the Test Client? below.
The Test Client tool built into the platform is a web-based REST client that allows you to test different APIs in the context of an app. You can use it to try out any API that your app has a contract with, or to try out an API in the context of an app you have visibility of, or even without an app context if the API supports anonymous access.
Test Client is available:
Test Client supports simple testing of an app against an API. However, it also supports more complex variations that there might be in the rules governing use of a specific API. It supports many more options than its predecessor in earlier versions of the platform, Dev Console. This allows you to much more realistically emulate, and therefore test, the actual conditions of the app/API interaction at runtime.
Of course, if a specific API doesn't support specific functionality, you won't see those options available for selection in Test Client. For example, if the API supports OAuth, but only supports OAuth 2.0 and only two grant types, you'll only see those specific choices available.
Assuming that a specific API supports these features, Test Client supports the following:
Again—when you're using Test Client, you probably won't see all the above options. You only see the options available to you, and that depends on the API you're testing with.
For specific information about the above options, how they're set up, and how to determine the values, you should choose, refer to the referenced sections.
Most or all APIs on the platform have the API Consumer Application Security Policy assigned. This policy is used to identify (authenticate) the app. Depending on how the policy is set up by the Administrator, you can authenticate with an ID and Shared Secret value, or you can upload a certificate. If the API supports it, you can also test the API in an anonymous context.
Specific APIs might have other security policies assigned. The policies assigned to the API you're using will affect the settings and options you'll see in Test Client. For specifics, refer to the API documentation.
When your application is connected to an API (through the Access request process), the application security credentials you've assigned to your app (via App Details > Security Credentials) work in conjunction with the API security policies. The request message that is sent to the API must conform to the security policies assigned to the API or the request will fail.
Note: If your app's contract with an API includes one or more licenses, Test Client displays only the operations that the app has permission to access based on the license governing the contract.
You can use Test Client to:
Before using Test Client:
The Test Client includes an API drop-down that displays a list of the APIs that your app is currently connected to. When you select an API from the drop-down, the platform analyzes the API configuration and the security policies assigned to the API and populates the fields with the appropriate information. After the Test Client is populated, you configure each test case and then click Run.
More information:
The basic input options in Test Client are shown below. For explanations, refer to the table below.
# | Field | Details |
---|---|---|
1 | API/Environment | The drop-down list is populated with one or more APIs and environments that are available for testing. |
2 | Operation (includes HTTP method) | Once you've specified the API/environment, the Operations drop-down list is populated with one or more operations for you to choose from. If your app's contract with the API is governed by a license, you'll only see the operations you have permission to use. |
3 | Endpoint / Path | The endpoint is defaulted based on your selections. If more than one endpoint is available, you can choose. The path includes all the query and path parameters in parentheses (for example, {}) |
4 | Headers | In the Headers section, the information displayed varies according to the API definition for the operation you selected. For example, if the operation only accepts a Content-Type of application/json, that is the only choice. If multiple media types are available, for Content-Type, Accept, or any other headers defined for the operation, you can choose from a drop-down list.
|
5 | Parameters | The Parameters section varies according to the type of operation you've selected and the specifics of that operation. Some examples: If the operation is a GET and the path includes a {WidgetID} parameter, enter the WidgetID on the Value line. If the operation is a POST or PUT, you'll have a field where you can paste the body content. |
6 | Parameter type | The type of parameter being sent. Possible values for all scenarios are Path, Query, or Form:
The possible values for your specific test scenario are determined by the API definition and your selections and values in Test Client. If you specify a POST or PUT operation, you can specify the POST or PUT content. |
8 | URL | The URL that the test message will be sent to. The URL that's displayed is generated based on the information entered in earlier fields; however, you can change the URL to experiment with the API if you want to. |
9 | Security | Click to set up your app's security credentials. For more information, see Test Client Security Settings below. |
10 | Config | Click to set up your app's security settings. For more information, see Test Client: Config Settings below. |
11 | Request/Response | When you click Run, the request and response are displayed. Use this information to test and debug as needed. There are several response tabs available: Raw, Formatted, Pretty, Headers, and Trace. For more information, see What are the different ways I can view the response information in Test Client? below. |
The Test Client testing tool allows you to test any API you have access to, with the following options:
To test your app in Test Client, follow the steps below.
When you click Run, the request and response are displayed. You can use this information to test and debug as needed. You can also click the tabs to see different formats or additional information:
An example of a successful response show in in the Raw tab is shown below.
The same message in the Formatted tab looks like this:
If your app will be using OAuth, it's a good idea to test in Test Client to make sure everything is working properly.
First, you'll need to make sure that the API supports OAuth 2.0, and supports this specific grant type. Check the API documentation.
OAuth values are set up in the second page of the Security Settings wizard. In Test Client, first set up the app/API information and the app credentials, and then you're ready to try out OAuth.
The procedure below takes you to the OAuth options. Then, follow the applicable linked procedure to test with a specific OAuth version, grant type, or other option.
If your app will be using OAuth, it's a good idea to test in Test Client to make sure everything is working properly.
First, you'll need to make sure that the API supports OAuth 1.0a. Check the API documentation.
If your app will be using OAuth, it's a good idea to test in Test Client to make sure everything is working properly.
First, you'll need to make sure that the API supports OAuth 2.0, and supports this specific grant type. Check the API documentation.
With the Authorization Code grant type, an authorization code is returned to the client through a browser redirect after the resource owner gives consent to the OAuth Authorization Server. The client then exchanges the authorization code for an access token.
If your app will be using OAuth, it's a good idea to test in Test Client to make sure everything is working properly.
First, you'll need to make sure that the API supports OAuth 2.0, and supports this specific grant type. Check the API documentation.
With the Implicit grant type, an access token is returned to the client through a browser redirect in response to the resource owner authorization request. This grant type is suitable for clients that do not support keeping client credentials confidential (for use in authenticating with the OAuth Authentication Server) such as client applications implemented in a browser using a scripting language like JavaScript.
If your app will be using OAuth, it's a good idea to test in Test Client to make sure everything is working properly.
First, you'll need to make sure that the API supports OAuth 2.0, and supports this specific grant type. Check the API documentation.
With the Resource Owner Password Credentials grant type, the client collects the resource owner's password and exchanges it at the OAuth authorization server for an access token, and often also a refresh token. This grant type is suitable in cases where the resource owner has a trust relationship with the client, such as its computer operation system or a highly privileged application, since the client must discard the password after using it to obtain the access token.
If your app will be using OAuth, it's a good idea to test in Test Client to make sure everything is working properly.
First, you'll need to make sure that the API supports OAuth 2.0, and supports this specific grant type. Check the API documentation.
With the Client Credentials grant type, the client presents its own credentials to the OAuth Authorization Server in order to obtain an access token. This access token is either associated with the client's own resources, rather than a specific resource owner, or is associated with a resource owner for whom the client is otherwise authorized to act.
If the API you're using sets the cache-control response header, the response message is cached. When you send multiple requests, the first response is cached for the time specified as the value in the API's cache-control response header, and you may see the same response for all subsequent requests until the cache expires. This could mean that when you send a subsequent request, the response you see is from the cache, not from the server. If this happens, there will only be one transaction log entry, even if you click the Run button multiple times, until the cache expires or is cleared.
To make sure you are always seeing the latest information, clear your browser cache before sending subsequent requests.
Tip: If the API you're testing doesn't have issues with additional query parameters (ignores them rather than returning an error), you can add a query parameter with any name/value. This forces the browser to retrieve a new response rather than using the cached response. This is a better solution than clearing the browser cache in scenarios where there is any caching done in a forward HTTP proxy (or in a CDN), since clearing the browser cache does not clear the cache from these intermediaries.
If you're not sure whether the API caches or not, send two requests and then check the logs for your app (if logs are available for messages to the API you're working with). If both transactions show up, caching is not an issue. If you see only one transaction, it means that the second was served from cache.
The following procedure provides a simple example of how to use the Test Client to test authorizing your app with OAuth and then sending a request.
How to get there: In Test Client, specify the API and operation you want to test, and any other applicable values (exact choices depend on the specific API). Click the Security button as shown below.
The table below shows the configuration values in the Test Client Security window.
Field... | Values... |
---|---|
Apps | When testing in the context of an app, choose the app. |
App ID | The unique ID that identifies your app to the API, that will be used for the request. If it is blank, you will need to go to the API provider directly and read their instructions for getting an App ID. |
Shared Secret | The unique shared secret value that validates your app with the API, that will be used for the request. If it is blank, you'll need to enter your app's shared secret value. If you don't have a shared secret on the platform, go to the API provider directly and get a Shared Secret value for your app. |
Upload Keystore | Check this box to upload a keystore file. You'll see these additional fields:
|
How to get there: In Test Client, specify the API and operation you want to test, and any other applicable values (exact choices depend on the specific API). Specify the app credentials, and then click the Config button.
The options you'll see depend on the settings for the specific API you've chosen, and for your app's contract with the API. Possible options are explained in the tables below.
A policy defines a set of rules that will be applied to your app's contract with the API. Different policies that might be part of the API definition require different information for testing your app in Test Client. Refer to the tables below. Possible options include:
The possible security settings for the AtmosphereApplicationSecurityPolicy are shown below. Specific values vary according to the specific scenario.
The table below shows the configuration values in the Security Settings window if the AtmosphereApplicationSecurityPolicy policy is applied to the API.
Field... | Values... |
---|---|
Token Location | Indicates how the token is added to the message: Header, QueryString, Form, or Cookie. The Form parameter is only applicable for POST or PUT. |
Token Algorithm | The algorithm to be used for generating the security token to be sent to the API endpoint. |
The table below shows the configuration values in the Security Settings window if the OAuth policy is applied to the API.
Field... | Values... |
---|---|
OAuth Version | Choose from OAuth versions supported by the API. |
Grant Type | OAuth 2.0 defines four grant types (security scenarios, or use cases). Choose from the list of grant types supported by the API. For more information, refer to the spec: http://oauth.net/2/. |
Authentication Method | Choose from authentication methods supported by the API. |
Get Token button | Click to get an access token from the API’s identity provider, so your app can access the API. Test Client will add the access token to each request. You might need to log in to the identity provider. |
Renew Token button | If the token has expired, click to get a renew token from the API’s identity provider, so your app can access the API. You might need to log in to the identity provider. |
The table below shows the configuration values in the Security Settings window if the SameOriginPolicy policy is applied to the API.
Field... | Values... |
---|---|
SameOriginPolicy: API Supports CORS | If the endpoint URL is on a host that is not the user interface host, same-origin policy will prevent the browser from accepting the response unless the API can send the CORS headers. Check this box if the API supports CORS. If it doesn't, clear the box and the request will be proxied. |
Authorization Endpoint Extension Parameters | If your OAuth provider requires any additional parameters to be sent to the authorization endpoint, beyond the OAuth specification, enter the parameter names here. Test Client shows these parameters to collect the values from developers. |
If the API you're using supports basic or detailed logging of transactions, the calls you make to an API in Test Client are recorded on the metric logs for your app.
In general, there is one log entry per transaction. However, if the API call you're making in Test Client returns more complex media types that cannot be accurately displayed in the Raw and Formatted tabs, yet the browser can determine the media type, the browser makes a second call in order to be able to display the response, within an <img> tag, in the Pretty tab.
For example, let's say the API response is an image, but the media types for the operation are not specified. Test Client makes the first call, and an image is returned. Test Client makes a second call and, as a result, can display the image in the Pretty tab.
The API you're testing might have special functionality associated with it to allow API requests from other domains; this is called CORS (Cross-Origin Resource Sharing). If the API supports CORS, you might see some additional headers in the response, along the lines of the examples below:
Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, DELETE, PUT Access-Control-Allow-Headers: Content-Type, api_key, Authorization
The above headers do the following:
This section provides information on some of the error messages you might see in Test Client if your test API call fails, and some possible reasons.
Error | Possible reason |
---|---|
400 Bad Request | You didn't set up the credentials for your app. Click the Security button to verify your credentials. Then click the Config button, set or verify values, and click Run. You will also see this error if you didn't specify an app, or specified Anonymous, when the API doesn't support anonymous access. |
Unauthorized | You didn't provide the correct AppID/Shared Secret or other credentials required by the API. |
Binding failure | The media type specified for the Accept header isn't supported by the operation. For example, the operation returns application/json only, but the Accept header field specifies a media type of application/xml. |
Missing domain. The service may not have been assigned a provider. | A step in the API's OAuth setup is incomplete. For help, contact the Administrator for the API. |
TokenKey does not have Policy Type (OAuth 1.0a or OAuth 2.0) | The API definition includes the OAuthSecurity policy, but you didn't click the Config button, choose OAuth settings, and generate the token. |