autoapi

package module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 11 Imported by: 0

README

auto-api-client-go

Go Reference Go Version License

Go client for auto-api.com — car listings from 8 marketplaces (encar, mobile.de, autoscout24, che168, dongchedi, guazi, dubicars, dubizzle).

No external dependencies. Stdlib net/http + encoding/json only. Supports context for timeouts and cancellation.

Installation

go get github.com/autoapicom/auto-api-go

Usage

import "github.com/autoapicom/auto-api-go"

client := autoapi.NewClient("your-api-key")
ctx := context.Background()
Get filters
filters, err := client.GetFilters(ctx, "encar")
Search offers
offers, err := client.GetOffers(ctx, "mobilede", &autoapi.OffersParams{
    Page:     1,
    Brand:    "BMW",
    YearFrom: 2020,
})

// Pagination
fmt.Println(offers.Meta.Page)
fmt.Println(offers.Meta.NextPage)
Get single offer
offer, err := client.GetOffer(ctx, "encar", "40427050")
Track changes
changeID, err := client.GetChangeID(ctx, "encar", "2025-01-15")
changes, err := client.GetChanges(ctx, "encar", changeID)

// Next batch
nextBatch, err := client.GetChanges(ctx, "encar", changes.Meta.NextChangeID)
Get offer by URL
info, err := client.GetOfferByURL(ctx, "https://encar.com/dc/dc_cardetailview.do?carid=40427050")
Decode offer data

Each marketplace returns different fields, so OfferItem.Data is json.RawMessage. Unmarshal it yourself:

for _, item := range offers.Result {
    var d autoapi.OfferData
    json.Unmarshal(item.Data, &d)
    fmt.Printf("%s %s %s — $%s\n", d.Mark, d.Model, d.Year, d.Price)
}
Error handling
import "errors"

offers, err := client.GetOffers(ctx, "encar", &autoapi.OffersParams{Page: 1})
if err != nil {
    var authErr *autoapi.AuthError
    var apiErr *autoapi.ApiError
    if errors.As(err, &authErr) {
        // 401/403 — invalid API key
    } else if errors.As(err, &apiErr) {
        fmt.Println(apiErr.StatusCode, apiErr.Message)
    }
}

Supported sources

Source Platform Region
encar encar.com South Korea
mobilede mobile.de Germany
autoscout24 autoscout24.com Europe
che168 che168.com China
dongchedi dongchedi.com China
guazi guazi.com China
dubicars dubicars.com UAE
dubizzle dubizzle.com UAE

Other languages

Language Package
PHP autoapi/client
TypeScript @autoapicom/client
Python autoapicom-client
C# AutoApi.Client
Java auto-api-client
Ruby auto-api-client
Rust auto-api-client

Documentation

auto-api.com

Documentation

Overview

Package autoapi provides a client for the auto-api.com car listings API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiError

type ApiError struct {
	StatusCode int
	Message    string
	Body       json.RawMessage
}

ApiError represents a non-auth API error response.

func (*ApiError) Error

func (e *ApiError) Error() string

type AuthError

type AuthError struct {
	StatusCode int
	Message    string
}

AuthError represents an authentication error (401/403).

func (*AuthError) Error

func (e *AuthError) Error() string

type ChangeIDResponse

type ChangeIDResponse struct {
	ChangeID int `json:"change_id"`
}

ChangeIDResponse is the response from GetChangeID.

type ChangeItem

type ChangeItem struct {
	ID         int             `json:"id"`
	InnerID    string          `json:"inner_id"`
	ChangeType string          `json:"change_type"`
	CreatedAt  string          `json:"created_at"`
	Data       json.RawMessage `json:"data"`
}

ChangeItem is a single item in the changes result array.

type ChangesMeta

type ChangesMeta struct {
	CurChangeID  int `json:"cur_change_id"`
	NextChangeID int `json:"next_change_id"`
	Limit        int `json:"limit"`
}

ChangesMeta holds pagination info for changes.

type ChangesResponse

type ChangesResponse struct {
	Result []ChangeItem `json:"result"`
	Meta   ChangesMeta  `json:"meta"`
}

ChangesResponse is the response from GetChanges.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the auto-api.com API client.

func NewClient

func NewClient(apiKey string) *Client

NewClient creates a new API client with the given API key.

func (*Client) GetChangeID

func (c *Client) GetChangeID(ctx context.Context, source string, date string) (int, error)

GetChangeID returns a change_id for the given date (format: yyyy-mm-dd).

func (*Client) GetChanges

func (c *Client) GetChanges(ctx context.Context, source string, changeID int) (*ChangesResponse, error)

GetChanges returns a changes feed (added/changed/removed) starting from change_id.

func (*Client) GetFilters

func (c *Client) GetFilters(ctx context.Context, source string) (map[string]interface{}, error)

GetFilters returns available filters for a source (brands, models, body types, etc.)

func (*Client) GetOffer

func (c *Client) GetOffer(ctx context.Context, source string, innerID string) (*OffersResponse, error)

GetOffer returns a single offer by inner_id.

func (*Client) GetOfferByURL

func (c *Client) GetOfferByURL(ctx context.Context, offerURL string) (map[string]interface{}, error)

GetOfferByURL returns offer data by its URL on the marketplace.

func (*Client) GetOffers

func (c *Client) GetOffers(ctx context.Context, source string, params *OffersParams) (*OffersResponse, error)

GetOffers returns a paginated list of offers with optional filters.

func (*Client) SetAPIVersion

func (c *Client) SetAPIVersion(version string)

SetAPIVersion overrides the default API version (default: "v2").

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(baseURL string)

SetBaseURL overrides the default base URL.

type Meta

type Meta struct {
	Page     int `json:"page"`
	NextPage int `json:"next_page"`
	Limit    int `json:"limit"`
}

Meta holds pagination info for offers.

type OfferData

type OfferData struct {
	InnerID          string   `json:"inner_id"`
	URL              string   `json:"url"`
	Mark             string   `json:"mark"`
	Model            string   `json:"model"`
	Generation       string   `json:"generation"`
	Configuration    string   `json:"configuration"`
	Complectation    string   `json:"complectation"`
	Year             string   `json:"year"`
	Color            string   `json:"color"`
	Price            string   `json:"price"`
	KmAge            string   `json:"km_age"`
	EngineType       string   `json:"engine_type"`
	TransmissionType string   `json:"transmission_type"`
	BodyType         string   `json:"body_type"`
	Address          string   `json:"address"`
	SellerType       string   `json:"seller_type"`
	IsDealer         bool     `json:"is_dealer"`
	Displacement     string   `json:"displacement"`
	OfferCreated     string   `json:"offer_created"`
	Images           []string `json:"images"`
}

OfferData holds common offer fields shared across all sources. Since each source may have additional fields, use json.RawMessage from OfferItem.Data and unmarshal into your own struct if needed.

type OfferItem

type OfferItem struct {
	ID         int             `json:"id"`
	InnerID    string          `json:"inner_id"`
	ChangeType string          `json:"change_type"`
	CreatedAt  string          `json:"created_at"`
	Data       json.RawMessage `json:"data"`
}

OfferItem is a single item in the offers result array.

type OffersParams

type OffersParams struct {
	Page          int    `url:"page"`
	Brand         string `url:"brand,omitempty"`
	Model         string `url:"model,omitempty"`
	Configuration string `url:"configuration,omitempty"`
	Complectation string `url:"complectation,omitempty"`
	Transmission  string `url:"transmission,omitempty"`
	Color         string `url:"color,omitempty"`
	BodyType      string `url:"body_type,omitempty"`
	EngineType    string `url:"engine_type,omitempty"`
	YearFrom      int    `url:"year_from,omitempty"`
	YearTo        int    `url:"year_to,omitempty"`
	MileageFrom   int    `url:"mileage_from,omitempty"`
	MileageTo     int    `url:"mileage_to,omitempty"`
	PriceFrom     int    `url:"price_from,omitempty"`
	PriceTo       int    `url:"price_to,omitempty"`
}

OffersParams holds query parameters for GetOffers.

type OffersResponse

type OffersResponse struct {
	Result []OfferItem `json:"result"`
	Meta   Meta        `json:"meta"`
}

OffersResponse is the response from GetOffers.

Directories

Path Synopsis
Auto API Go Client — Complete usage example.
Auto API Go Client — Complete usage example.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL