GraphQL API Guide

The Cleverbridge GraphQL API is an alternative to the collection of REST APIs that we offer. By switching to the GraphQL API, you can take advantage of a number of its features, including the following:

  • Better query efficiency — You can now access numerous resources from a single endpoint.
  • No unnecessary data — It is now possible to get exactly what you need in a compact, concise payload.
  • More stability — GraphQL isn't tied to any specific database or storage engine. Instead, it is based on existing code and data.
    At the moment, the GraphQL API can help you manage your customers, products and prices. As a result, you can use this API to renew customer license keys, resend customer emails, and update product descriptions, etc. After the integration, you can also use this tool to create customer self-service options and ensure that your internal product catalog is up-to-date.
    To start using the API and learn more about its capabilities, see the following:

GraphQL vs. REST

The following examples illustrate some of the benefits of using our GraphQL API in comparison to the Cleverbridge Pricing API. As demonstrated in the REST examples, you not only have to call a specific endpoint to obtain product and pricing information but the content of the payload is standard, large, and tied to the /prices resource.

REST example to one endpoint

Rest Request

curl --request GET \
   --url 'https://pricingapi.cleverbridge.com/prices?client_id=864&product_id=97771&currency=USD&country=US' \
   --header 'accept-language: en-US'

REST Response

On the other hand, when using GraphQL, you can call one single endpoint and precisely define which data the API should return. This results in a smaller, more manageable payload.

[
  {
    "client_id": "864",
    "product_id": "97771",
    "locale": "en-US",
    "currency": {
      "symbol": "$",
      "iso": "USD"
    },
    "price": {
      "net": {
        "localized": "$5.99",
        "value": 5.99
      },
      "vat": {
        "localized": "$0.00",
        "value": 0
      },
      "gross": {
        "localized": "$5.99",
        "value": 5.99
      }
    },
    "product": {
      "name": "Internet Security Basic Extended",
      "additional_name": "For your home",
      "short_description": "Internet Security Basic Extended offers virus protection, anti-phishing tools, mail protection, and identity theft protection.",
      "description": "Internet Security Basic Extended offers virus protection, anti-phishing tools, mail protection, and identity theft protection. ",
      "system_requirements": "867 MHz or faster processor\r\n512MB of RAM; 1GB recommended"
    },
    "price_country": "US",
    "vat_rate": {
      "value": 0,
      "localized": "0%"
    }
  }
]

GraphQL example with one query object

GraphQL Query

query {
  cart(
    cartInput: {
      cartItems: { productId: 97771 }
      countryId: US
      currencyId: USD
      languageId: EN
      clientId: 864
    }
  ) {
    remoteIpAddress
    totalPrice {
      net {
        localized
        value
      }
    }
    language {
      isoCode
    }
    locale
    userLanguages
    cartItems {
      discount {
        absolute {
          net {
            localized
            value
          }
        }
      }
    }
  }
}

GraphQL Response

{
  "data": {
    "cart": {
      "remoteIpAddress": "10.0.7.54",
      "totalPrice": {
        "net": {
          "localized": "$5.99",
          "value": 5.99
        }
      },
      "language": {
        "isoCode": "en"
      },
      "locale": "en-US",
      "userLanguages": [
        "en-US",
        "en;q=0.9",
        "fr;q=0.8",
        "de;q=0.7"
      ],
      "cartItems": [
        {
          "discount": {
            "absolute": {
              "net": {
                "localized": "$0.00",
                "value": 0
              }
            }
          }
        }
      ]
    }
  }
}

If necessary, you can also call an additional resource in the same request (for example, biBookmark). In REST, you would have to make two separate calls to two independent endpoints.