# Sync

## Introduction

This tutorial will teach you how to update all your locations' data across your website, landing pages and online directories by using the uberall API.

## Common Endpoints

| Method | Endpoint | Description |
|  --- | --- | --- |
| POST | `/businesses` | Creates a new business |
| GET | `/businesses` | Search and filter businesses |
| POST | `/locations` | Creates a new location |
| PATCH | `/locations/$id` | Updates the given location |
| PATCH | `/locations` | Updates the given locations |
| POST | `/businesses/$id/locations/sync` | Starts a sync on all directories for all locations for the given business |
| POST | `/locations/$id/sync` | Starts a sync on all directories for the given location |


## Businesses/accounts

A business/account contains one or more locations. All locations have to be linked to a business. If you have not already created businesses/accounts, you can create one manually from uberall ("Accounts">"Create new account") or use `/businesses` POST request as shown in the example below.


```bash
curl -X POST -H "Content-Type: application/json" -H "privateKey: $privateKey" -H "Cache-Control: no-cache" -d '{
  "identifier":"bus_0000001",
  "name": "uberall GmBH",
  "type": "SMB",
  "streetAndNo": "Oranienburgerstr. 66",
  "zip": "10117",
  "country": "DE",
  "productPlan": $planID,
  "amountPOI": 5,
  "contractDuration": 12,
  "city": "Berlin"
```

Now you can use `/businesses` GET request to get the list of your accounts.


```bash
curl -X GET 'https://sandbox.uberall.com/api/businesses' -H 'privateKey: $privateKey' -H 'Cache-Control: no-cache'
```

Business objects contain the list of directories where appertaining locations will be updated:


```json
{
  "status": "SUCCESS",
  "response": {
    "offset": 0,
    "max": 50,
    "count": 261,
    "businesses": [
      {
        "id": 30829,
        "identifier": "bus_0001",
        "name": "uberall GmBH",
        "streetAndNo": "Oranienburgerstr. 66",
        "zip": "10117",
        "productPlan": {
          "updatedDirectories": [
            "INFOBEL", "WEB_DE" //,...
          ] //,...
        }
      } //,...
    ]
  }
}
```

## Create & update locations

We are going to use `/locations` POST request to create one location inside the account we have just created.


```bash
curl -H "Content-Type: application/json" 'https://sandbox.uberall.com/api/locations' -X POST -d '{
    "businessId": 30829,
    "name" : "uberall",
    "street" : "Oranienburgerstrasse",
    "streetNo": 66,
    "zip": 10117,
    "city" : "Berlin"
}' -H 'privateKey: $privateKey' -H 'Cache-Control: no-cache'
```


```json
{
  "status": "SUCCESS",
  "response": {
    "location": {
      "id": 301626, //...
    }
  }
}
```

Update it using `/locations/$id` PATCH request.


```bash
curl -H "Content-Type: application/json" 'https://sandbox.uberall.com/api/locations/301626' -X PATCH -d '{
    "website": "https://uberall.com"
}' -H 'privateKey: $privateKey' -H 'Cache-Control: no-cache'
```

You will also need to provide a category for the location. You can retrieve all the categories with GET `/categories/`


```bash
curl -H "Content-Type: application/json" 'https://sandbox.uberall.com/api/categories?language=en' -X GET -H 'privateKey: $privateKey' -H 'Cache-Control: no-cache'
```

## Sync on all directories

Before syncing locations, we need to activate them. Just use /locations/$id PATCH request with the following payload:


```json
{
    "status" : "ACTIVE"
}
```

> **NEEDS_REVIEW status** : Beware that locations with the NEEDS_REVIEW status can't be activated.


> **Demo accounts** : Beware that locations in demo accounts can't sync. You will get a "Location not available for sync" error message.


Use `businesses/$id/locations/sync` or `/locations/$id/sync` to start a sync on all directories for all locations related to a specific business or a specific location.


```bash
curl -H "Content-Type: application/json" 'https://sandbox.uberall.com/api/locations/301767/sync' -X POST -d '{}' -H 'privateKey: $privateKey' -H 'Cache-Control: no-cache'
```