Skip to content

locationCreate

Required scope: create_locations

Creates a new location. New locations default to type INTERNAL and active: true unless specified otherwise.


Mutation

graphql
mutation LocationCreate($input: LocationCreateInput!) {
  locationCreate(input: $input) {
    id
    name
    title
    locationType
    active
  }
}

Input: LocationCreateInput

FieldTypeRequiredDescription
organizationIdStringYesUUID of the organization that owns this location
nameStringYesUnique slug identifier (e.g. paris-warehouse). Must be unique within the organization.
titleStringNoHuman-readable display name
descriptionStringNoFree-text description
locationTypeLocationTypeEnumNoINTERNAL (default) or WAREHOUSE
activeBooleanNoWhether the location is active on creation. Defaults to true.
socialReasonStringNoLegal company name
addressStringNoStreet address line 1
addressComplementStringNoStreet address line 2
zipCodeStringNoZip or postal code
cityStringNoCity
countryStringNoISO 3166-1 alpha-2 country code (e.g. FR)
phoneStringNoContact phone number
emailStringNoContact email address

Example

Variables

json
{
  "input": {
    "organizationId": "org_123",
    "name": "paris-warehouse",
    "title": "Paris Warehouse",
    "description": "Main warehouse in Paris",
    "locationType": "INTERNAL",
    "active": true,
    "socialReason": "My Company SAS",
    "address": "123 Rue de la Logistique",
    "zipCode": "75001",
    "city": "Paris",
    "country": "FR",
    "phone": "+33123456789",
    "email": "warehouse@mycompany.com"
  }
}

Response

json
{
  "data": {
    "locationCreate": {
      "id": "loc_123",
      "name": "paris-warehouse",
      "title": "Paris Warehouse",
      "locationType": "INTERNAL",
      "active": true
    }
  }
}

Code Examples

bash
curl -X POST https://api-v3.happycolis.com/graphql \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "mutation LocationCreate($input: LocationCreateInput!) { locationCreate(input: $input) { id name title locationType active } }",
    "variables": {
      "input": {
        "organizationId": "org_123",
        "name": "paris-warehouse",
        "title": "Paris Warehouse",
        "locationType": "INTERNAL",
        "active": true,
        "address": "123 Rue de la Logistique",
        "zipCode": "75001",
        "city": "Paris",
        "country": "FR"
      }
    }
  }'
js
async function createLocation(accessToken, input) {
  const response = await fetch('https://api-v3.happycolis.com/graphql', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${accessToken}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      query: `
        mutation LocationCreate($input: LocationCreateInput!) {
          locationCreate(input: $input) {
            id
            name
            title
            locationType
            active
          }
        }
      `,
      variables: { input },
    }),
  });

  const { data, errors } = await response.json();
  if (errors) throw new Error(errors[0].message);
  return data.locationCreate;
}

// Usage
const location = await createLocation(accessToken, {
  organizationId: 'org_123',
  name: 'paris-warehouse',
  title: 'Paris Warehouse',
  locationType: 'INTERNAL',
  active: true,
  address: '123 Rue de la Logistique',
  zipCode: '75001',
  city: 'Paris',
  country: 'FR',
});
python
import requests

def create_location(access_token, input_data):
    response = requests.post(
        'https://api-v3.happycolis.com/graphql',
        headers={
            'Authorization': f'Bearer {access_token}',
            'Content-Type': 'application/json',
        },
        json={
            'query': '''
                mutation LocationCreate($input: LocationCreateInput!) {
                    locationCreate(input: $input) {
                        id
                        name
                        title
                        locationType
                        active
                    }
                }
            ''',
            'variables': {'input': input_data},
        },
    )
    result = response.json()
    if 'errors' in result:
        raise Exception(result['errors'][0]['message'])
    return result['data']['locationCreate']

# Usage
location = create_location(access_token, {
    'organizationId': 'org_123',
    'name': 'paris-warehouse',
    'title': 'Paris Warehouse',
    'locationType': 'INTERNAL',
    'active': True,
    'address': '123 Rue de la Logistique',
    'zipCode': '75001',
    'city': 'Paris',
    'country': 'FR',
})
php
function createLocation(string $accessToken, array $input): array
{
    $client = new \GuzzleHttp\Client();

    $response = $client->post('https://api-v3.happycolis.com/graphql', [
        'headers' => [
            'Authorization' => 'Bearer ' . $accessToken,
            'Content-Type'  => 'application/json',
        ],
        'json' => [
            'query' => '
                mutation LocationCreate($input: LocationCreateInput!) {
                    locationCreate(input: $input) {
                        id
                        name
                        title
                        locationType
                        active
                    }
                }
            ',
            'variables' => ['input' => $input],
        ],
    ]);

    $result = json_decode($response->getBody()->getContents(), true);
    if (isset($result['errors'])) {
        throw new \Exception($result['errors'][0]['message']);
    }
    return $result['data']['locationCreate'];
}

// Usage
$location = createLocation($accessToken, [
    'organizationId' => 'org_123',
    'name'           => 'paris-warehouse',
    'title'          => 'Paris Warehouse',
    'locationType'   => 'INTERNAL',
    'active'         => true,
    'address'        => '123 Rue de la Logistique',
    'zipCode'        => '75001',
    'city'           => 'Paris',
    'country'        => 'FR',
]);
go
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

type LocationCreateInput struct {
    OrganizationID string  `json:"organizationId"`
    Name           string  `json:"name"`
    Title          *string `json:"title,omitempty"`
    Description    *string `json:"description,omitempty"`
    LocationType   *string `json:"locationType,omitempty"`
    Active         *bool   `json:"active,omitempty"`
    SocialReason   *string `json:"socialReason,omitempty"`
    Address        *string `json:"address,omitempty"`
    ZipCode        *string `json:"zipCode,omitempty"`
    City           *string `json:"city,omitempty"`
    Country        *string `json:"country,omitempty"`
    Phone          *string `json:"phone,omitempty"`
    Email          *string `json:"email,omitempty"`
}

func createLocation(accessToken string, input LocationCreateInput) (map[string]interface{}, error) {
    query := `
        mutation LocationCreate($input: LocationCreateInput!) {
            locationCreate(input: $input) {
                id
                name
                title
                locationType
                active
            }
        }
    `

    body, _ := json.Marshal(map[string]interface{}{
        "query":     query,
        "variables": map[string]interface{}{"input": input},
    })

    req, _ := http.NewRequest("POST", "https://api-v3.happycolis.com/graphql", bytes.NewBuffer(body))
    req.Header.Set("Authorization", "Bearer "+accessToken)
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        return nil, err
    }
    defer resp.Body.Close()

    var result map[string]interface{}
    json.NewDecoder(resp.Body).Decode(&result)

    if errs, ok := result["errors"]; ok {
        return nil, fmt.Errorf("graphql error: %v", errs)
    }
    data := result["data"].(map[string]interface{})
    return data["locationCreate"].(map[string]interface{}), nil
}

HappyColis API Documentation