GuideAnleitungen/Rezepte/Create a location

Diese Anleitung ist auf Englisch verfügbar.

How do I create a business location via the API?

Create a Location with the Synup API

Create a business location under a client in one POST, get back a locationId, and know which fields matter and which can wait.

Auf einen Blick

Was diese Anleitung leistet
Create one location under a client and store the returned locationId against your own record.
Verwendete APIs
Referenz
Locations
Voraussetzungen
  • An API key with write access
  • The clientId the location belongs to
Typische Anwendungsfälle
  • Onboarding a new business into your product
  • Backfilling locations from an existing database
  • Adding a store to a multi-location account

A location needs three things to exist: the client it belongs to, a name, and a full street address. Send those to POST /api/v1/locations and you get back a 201 and a locationId. Everything else on the profile can be patched in afterwards, so don't hold up the create call waiting for hours or photos.

curl -X POST https://ai.synup.com/api/v1/locations \
  -H "Authorization: Bearer $SYNUP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "clientId": "CLIENT_ID",
    "name": "Grove Street Dental Mission",
    "countryIso": "US",
    "street": "88 Grove St",
    "city": "San Francisco",
    "stateIso": "CA",
    "postalCode": "94105",
    "phone": "+1 415 555 0142",
    "website": "https://grovestreetdental.example/downtown",
    "categoryName": "Dentist"
  }'
const API = "https://ai.synup.com/api/v1";
const headers = {
  Authorization: `Bearer ${process.env.SYNUP_API_KEY}`,
  "Content-Type": "application/json",
};

async function createLocation(clientId, profile) {
  const res = await fetch(`${API}/locations`, {
    method: "POST",
    headers,
    body: JSON.stringify({ clientId, ...profile }),
  });
  if (!res.ok) throw new Error(`${res.status}: ${(await res.json()).error}`);
  const { data } = await res.json();
  return data.locationId; // store this against your own record
}

await createLocation("CLIENT_ID", {
  name: "Grove Street Dental Mission",
  countryIso: "US",
  street: "88 Grove St",
  city: "San Francisco",
  stateIso: "CA",
  postalCode: "94105",
  phone: "+1 415 555 0142",
  website: "https://grovestreetdental.example/downtown",
  categoryName: "Dentist",
});
import os
import requests

API = "https://ai.synup.com/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['SYNUP_API_KEY']}"}

def create_location(client_id, profile):
    r = requests.post(f"{API}/locations", headers=HEADERS, timeout=30,
                      json={"clientId": client_id, **profile})
    r.raise_for_status()
    return r.json()["data"]["locationId"]

create_location("CLIENT_ID", {
    "name": "Grove Street Dental Mission",
    "countryIso": "US",
    "street": "88 Grove St",
    "city": "San Francisco",
    "stateIso": "CA",
    "postalCode": "94105",
    "phone": "+1 415 555 0142",
    "website": "https://grovestreetdental.example/downtown",
    "categoryName": "Dentist",
})

Two field names that are not obvious. The address country is countryIso and the state is stateIso, both ISO codes, not the spelled-out names a read hands back. And categoryName is fuzzy-matched against Synup's catalog. If you want an exact category, resolve its id first with GET /api/v1/locations/categories.

There is no storeCode on the create body. If you keep your own id for the location, patch it on afterwards with PATCH /api/v1/locations/{id}, and store the locationId you got back so you never have to guess the mapping.

Don't have the client yet? Create it with POST /api/v1/clients and use the id it returns. The full loop, from client to a location that is live on every publisher, is in the Business Listings API guide.