Skip navigation links

Package com.veeva.vault.sdk.api.http

This package provides interfaces to make HTTP callouts (to Vault or to an external service).

See: Description

Package com.veeva.vault.sdk.api.http Description

This package provides interfaces to make HTTP callouts (to Vault or to an external service).

To make an HTTP callout, you must first set up a Connection in Vault Admin. Connections can be set up for the local vault, with another vault, or with an external application. Local and Vault-to-Vault connection types can be set up with an Authorized Connection User to control what data access is allowed. External connection types may also be set up to make request with basic authentication using username and password tokens. Learn more about HTTP Callout in the Developer Portal.

The following is a simple example of a Vault-to-Vault callout:

     HttpService httpService = ServiceLocator.locate(HttpService.class);
      // Initialize a new http request with a connection named as "remote_vault_callout"
      // that references a connection to another vault
      HttpRequest httpRequest = httpService.newHttpRequest("remote_vault_callout");

      // Build the request object to perform a VQL query
      httpRequest.setBodyParam("q", "select name__v from product__v where name__v='CholeCap'");

      // Send the request and handle response to verify that a product record by name 'CholeCap' exists
      httpService.send(httpRequest, HttpResponseBodyValueType.JSONDATA).
      onError((e)-> {
          String errorMessage = e.getMessage();
          throw new RollbackException("PRODUCT_QUERY_ERROR", errorMessage);
      }).onSuccess((s) -> {
          // Retrieve json response
          JsonData jsonData = s.getResponseBody();
          JsonObject jsonObject = jsonData.getJsonObject();

          // Get response status
          String responseStatus = jsonObject.getValue("responseStatus", JsonValueType.STRING);

          if (responseStatus.equalsIgnoreCase("SUCCESS")) {
              JsonObject responseDetails = jsonObject.getValue("responseDetails", JsonValueType.OBJECT);
              BigDecimal size = responseDetails.getValue("size", JsonValueType.NUMBER);
              if (size.intValue() == 0) {
                  throw new RollbackException("PRODUCT_NOT_FOUND", "Product record by name 'CholeCap' not found");
          } else if (responseStatus.equalsIgnoreCase("FAILURE")) {
              JsonArray jsonArray = jsonObject.getValue("errors", JsonValueType.ARRAY);
              JsonObject error = jsonArray.getValue(0, JsonValueType.OBJECT);
              String errorMessage = error.getValue("message", JsonValueType.STRING);
              throw new RollbackException("PRODUCT_QUERY_ERROR", errorMessage);
          } else {
              throw new RollbackException("PRODUCT_QUERY_ERROR", "Unexpected error");
Skip navigation links

Copyright © Veeva Systems 2017–2019. All rights reserved.