# Real-Time Updates Ready

Inventory in your system changes because of new bookings, cancellations, and
schedule changes from your merchants. The Real-Time Update (RTU) API is a
mechanism to notify Google about these changes, and the changes made to existing
bookings.

RTUs are required in the following cases:

- When a user cancels a reservation on your system, and the slot becomes available.
- When a user books a reservation through the Actions Center, and the slot is no longer available.
- When a reservation made through the Actions Center is canceled on your side. An example situation includes a cancelation by the merchant directly. You need to update the booking and the availability, because the original slot is now available.

Complete the following RTU milestone task before you move to Sandbox review:

- [BookingNotification Ready](https://developers.google.com/actions-center/verticals/reservations/e2e/integration-steps/real-time-updates-ready/bookingnotification-ready)

Each task is marked completed and turns green when the last 20 requests have no
errors for a period of 14 days. Continue to send successful requests to ensure
that the milestone remains green.

## API RTU and Feeds

API RTUs notify Google about incremental changes to inventory availability and
bookings in real-time. In addition to RTUs, send complete Availability Feeds
daily. This ensures that Google has the most accurate and latest availability
information as it exists in your system. Complete Feeds act as a snapshot of the
latest state of inventory availability in your system.

For more information, see the following resources:

- [Structure RTUs](https://developers.google.com/actions-center/verticals/reservations/e2e/reference/real-time-updates-rest/rtu)

- [Java client example for RTUs using RESTful calls](https://maps-booking.googlesource.com/java-maps-booking-api-example/)

- [Inventory update API](https://developers.google.com/maps-booking/reference/maps-booking-api/rpc#google.maps.booking.v1alpha.inventoryupdate)

## Access the API

Your [Google Cloud](https://cloud.google.com/) project is how you access the
Actions Center's Maps Booking API, which is how you submit RTUs.
You must use a Google Account within the
[Google Developers console](https://console.developers.google.com/) and provide
your Cloud Project Number in the Setup milestone of your onboarding plan. For
more information on how to enable Cloud APIs, see
[Enable CloudAPIs](https://developers.google.com/actions-center/verticals/reservations/e2e/integration-steps/setup).

### Use RESTful calls or download the client library

We recommend that you make RESTful calls directly to the Maps Booking API with
JSON payloads. For more information, see [REST API documentation](https://developers.google.com/maps-booking/reference/maps-booking-api/rest).

You can also use client libraries to connect to the API.

| Language | Download link |
|---|---|
| Java | [Java client library](https://dl.google.com/mapsbooking/apiclients/v1alpha/mapsbooking_java_public.zip). For more information, see [Java client instructions](https://developers.google.com/actions-center/verticals/reservations/e2e/reference/real-time-updates-rest/java-rest) |

Additional [support libraries](https://developers.google.com/api-client-library)
that handle authorization and other aspects of calls to Google APIs are
available to download. For more information, see [Code Samples](https://developers.google.com/actions-center/verticals/reservations/e2e/reference/real-time-updates-rest/code-samples).

### Fetch the Discovery document

For some client libraries, such as Ruby, it's necessary to fetch the Discovery
document for the API that describes its methods and parameters.

To fetch the Discovery document, use the following command:

`curl -s -o mapsbooking_rest`

`https://mapsbooking.googleapis.com/$discovery/rest?version=v1alpha`

For more information on how to access the API from Ruby, see
[Ruby API Client](https://github.com/google/google-api-ruby-client) and
[Ruby Auth Library](https://github.com/google/google-auth-library-ruby).

### Make authorized calls to the API

When you make calls to the API, refer to [Preparing to make a delegated API call](https://developers.google.com/identity/protocols/OAuth2ServiceAccount#authorizingrequests)
to authorize your service account with your private key and the following OAuth
scope:

`https://www.googleapis.com/auth/mapsbooking`

## Sandbox and Production endpoints

You can make calls to both the Sandbox and Production environments through the
API. Make sure that you enable both APIs in your Google Cloud project. Both APIs
use the same scope, but they have different endpoints.

**Production endpoint** : `https://mapsbooking.googleapis.com/`

**Sandbox endpoint** : `https://partnerdev-mapsbooking.googleapis.com/`

The following is an example in Java of how to switch endpoints:

     // This block of code is for OAuth and is the same for prod and sandbox.
        GoogleCredential
          .fromStream(new FileInputStream(...))
          .createScoped(Collections.singleton("https://www.googleapis.com/auth/mapsbooking"))

        // This block of code sets the endpoint. This is what you'd change to connect to the sandbox.
        new GoogleMapsBookingAPI.Builder(...)
          .setApplicationName(...)
          .setRootUrl("https://partnerdev-mapsbooking.googleapis.com/") // you add this to change the endpoint to use partnerdev.
          .build()