Conventions

Every operation follows the same rules. Learn them once and every resource reads the same way.

Address and paths

Methods

IntentFormSuccess
ListGET /organizations/{id}/products200, a list
ReadGET …/products/{productId}200
CreatePOST /organizations/{id}/products201, Location, the resource
ChangePATCH …/products/{productId}, a JSON merge patch200, the resource
DeleteDELETE …/products/{productId}204, no body
Business actionPOST …/invoices/{invoiceId}/validate200, the resource

A GET never changes anything.

Ids

object

Every resource carries object, its kind: "object": "product". It is the id's prefix, spelled out.

Money, quantities and rates

Money is an object with a decimal string, never a floating-point number:

CLI

#!/usr/bin/env bash
# conventions-money: the myle CLI (key from `myle login` or MYLE_API_KEY).
# Money is a decimal string and its currency: jq keeps the string, never a float.
myle products retrieve product_2ab4c6e8-1f3d-4a5b-8c7d-9e0f1a2b3c4d \
  --organization organization_7f2c41d0-8a3b-4c6e-9f12-5d7e8a9b0c1d \
  | jq -r '.unitPrice // empty | "\(.amount) \(.currency)"'   # 45.00 EUR

JSON

"unitPrice": { "amount": "45.00", "currency": "EUR" }

TypeScript

import { Myle } from '@myleapp/myle';

const myle = new Myle();
const product = await myle.organization('organization_7f2c41d0-8a3b-4c6e-9f12-5d7e8a9b0c1d').products.get('product_2ab4c6e8-1f3d-4a5b-8c7d-9e0f1a2b3c4d');

// Money is a decimal string and its currency: hand it to a decimal library, never to a float.
if (product.unitPrice !== null) {
  console.log(product.unitPrice.amount, product.unitPrice.currency); // 45.00 EUR
}

Python

from decimal import Decimal

from myle import Myle

myle = Myle()
product = myle.organization("organization_7f2c41d0-8a3b-4c6e-9f12-5d7e8a9b0c1d").products.get("product_2ab4c6e8-1f3d-4a5b-8c7d-9e0f1a2b3c4d")

# Money is a decimal string and its currency: read it as a Decimal, never as a float.
if product.unit_price is not None:
    price = Decimal(product.unit_price.amount)
    print(price * 2, product.unit_price.currency)  # 90.00 EUR

Go

package main

import (
    "context"
    "fmt"
    "log"

    myle "github.com/myleapp/myle-go"
)

func main() {
    client := myle.NewClient()
    org := client.Organization("organization_7f2c41d0-8a3b-4c6e-9f12-5d7e8a9b0c1d")
    product, err := org.Products.Get(context.Background(), "product_2ab4c6e8-1f3d-4a5b-8c7d-9e0f1a2b3c4d")
    if err != nil {
        log.Fatal(err)
    }

    // Money is a decimal string and its currency: hand it to a decimal library, never to a float.
    if product.UnitPrice != nil {
        fmt.Println(product.UnitPrice.Amount, product.UnitPrice.Currency) // 45.00 EUR
    }
}

Java

import fr.myleapp.myle.MyleClient;
import fr.myleapp.myle.Product;
import java.math.BigDecimal;

public class Example {
    public static void main(String[] args) {
        MyleClient client = MyleClient.builder().build();
        Product product = client.organization("organization_7f2c41d0-8a3b-4c6e-9f12-5d7e8a9b0c1d").products().get("product_2ab4c6e8-1f3d-4a5b-8c7d-9e0f1a2b3c4d");

        // Money is a decimal string and its currency: read it as a BigDecimal, never as a double.
        if (product.unitPrice() != null) {
            BigDecimal price = new BigDecimal(product.unitPrice().amount());
            System.out.println(price.multiply(BigDecimal.valueOf(2)) + " " + product.unitPrice().currency()); // 90.00 EUR
        }
    }
}

Scala

import fr.myleapp.myle.MyleClient

object ConventionsMoney {
  def main(args: Array[String]): Unit = {
    val myle = MyleClient()
    val product = myle.organization("organization_7f2c41d0-8a3b-4c6e-9f12-5d7e8a9b0c1d").products.get("product_2ab4c6e8-1f3d-4a5b-8c7d-9e0f1a2b3c4d")

    // Money is a decimal string and its currency: hand it to BigDecimal, never to a Double.
    for (price <- product.unitPrice) {
      println(s"${price.amount} ${price.currency}") // 45.00 EUR
    }
  }
}

PHP

<?php

require __DIR__ . '/vendor/autoload.php';

use Myle\Client;

$myle = new Client();
$product = $myle->organization('organization_7f2c41d0-8a3b-4c6e-9f12-5d7e8a9b0c1d')->products->get('product_2ab4c6e8-1f3d-4a5b-8c7d-9e0f1a2b3c4d');

// Money is a decimal string and its currency: hand it to a decimal library (bcmath, brick/math), never to a float.
if ($product->unitPrice !== null) {
    echo $product->unitPrice->amount, ' ', $product->unitPrice->currency, "\n"; // 45.00 EUR
}

C#

using Myle;

using var client = new MyleClient();
var product = await client.Organization("organization_7f2c41d0-8a3b-4c6e-9f12-5d7e8a9b0c1d").Products.GetAsync("product_2ab4c6e8-1f3d-4a5b-8c7d-9e0f1a2b3c4d");

// Money is a decimal string and its currency: hand it to decimal, never to a double.
if (product.UnitPrice is not null)
{
    Console.WriteLine($"{product.UnitPrice.Amount} {product.UnitPrice.Currency}"); // 45.00 EUR
}

Quantities and rates are decimal strings too: "quantity": "12.5", "vatRate": "5.5". Read them with a decimal type (Decimal in Python, BigDecimal in Java, a decimal library in JavaScript), never as a float.

Dates and instants

Enums grow

Enum values are SCREAMING_SNAKE_CASE (ACTIVE, DRAFT) and listed in the reference. A new value can appear at any time: tolerate a value you do not know, treat it as “other”, never fail on it.

null and absent

Unknown fields

New fields are added to responses without notice. Ignore the fields you do not know; do not reject a response because of them.

Headers

What you send

HeaderUse
Authorization: Bearer <key>Your API key (Authentication).
Myle-API-Version: YYYY-MM-DDThe contract you built against; optional (Versioning).
Myle-Client: <name>/<version>Names your integration: my-export/1.0.0, sdk-js/1.2.0.
Idempotency-KeyOn a POST, makes a retry safe (Writes).
If-MatchOn a PATCH or DELETE, refuses to overwrite a change you have not seen.
Accept-Language: fr or enThe language of error messages; English when absent.
Content-Typeapplication/json; application/merge-patch+json for a PATCH.
traceparentW3C Trace Context; Myle continues your trace.

What you get

HeaderWhen
Myle-Request-IdAlways: the request's id in Myle's logs, for support.
RateLimit-Policy, RateLimitOn every response to a key, errors included (Rate limits).
Retry-AfterOn 429 and 503: seconds to wait.
ETagOn a single resource.
LocationOn 201: the new resource's path.
Content-LanguageOn an error: the language of its message.
Myle-Idempotent-Replayed: trueWhen a response is replayed for an Idempotency-Key.
Myle-API-Version, Deprecation, Sunset, LinkWhen an older behavior was served (Versioning).

Myle's own headers start with Myle-; standard headers keep their names.