package module
Version: v0.0.0-...-e842009 Latest Latest

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

Go to latest
Published: Jul 3, 2019 License: MIT Imports: 10 Imported by: 1


Steam API in Go

This package provides a simple API to the Steam API as documented in the TF2 Wiki.

You can find the documentation here.

It is licensed under the MIT license.



Package steamapi provides an interface to the Steam Web API methods.



View Source
const BaseSteamAPIURLProduction = ""

BaseSteamAPIURLProduction is the steam url used to do requests in prod


View Source
var BaseSteamAPIURL = BaseSteamAPIURLProduction

BaseSteamAPIURL is the url used to do requests, defaulted to prod

View Source
var (
	ErrInvalidId = errors.New("Invalid Steam ID")


func GetCurrentAppVersion

func GetCurrentAppVersion(app int) (uint, error)

func IEconActionTradeOffer

func IEconActionTradeOffer(action string, apiKey string, tradeOfferID uint64) error

IEconActionTradeOffer declines a TO created by someone else

func IEconCancelTradeOffer

func IEconCancelTradeOffer(apiKey string, tradeOfferID uint64) error

IEconCancelTradeOffer declines a TO created by someone else

func IsAppUpToDate

func IsAppUpToDate(app int, version uint) (bool, error)

func NewIdFrom32bit

func NewIdFrom32bit(i uint32) (id steamId)

func NewIdFrom64bit

func NewIdFrom64bit(i uint64) (id steamId)

func NewIdFromString

func NewIdFromString(s string) (id steamId, err error)

func NewIdFromVanityUrl

func NewIdFromVanityUrl(vanityUrl, apiKey string) (id steamId, err error)


type AccountInfo

type AccountInfo struct {
	SteamID     uint64 `json:",string"`
	PersonaName string

AccountInfo is id and name of user

type Asset

type Asset struct {
	Prices   map[string]int
	Defindex int `json:"name,string"`
	Date     string
	Tags     []string
	TagIDs   []int64

Asset is an item in the store.

func GetAssetPrices

func GetAssetPrices(appid uint64, language, currency, apiKey string) ([]Asset, error)

GetAssetPrices returns a list of assets with their prices

func (*Asset) HasTag

func (i *Asset) HasTag(tag string) bool

HasTag return bool if the asset has a tag

type Attribute

type Attribute struct {
	Defindex    uint32
	Value       interface{}  `json:"value"`
	FloatValue  float64      `json:"float_value,omitempty"`
	AccountInfo *AccountInfo `json:",omitempty"`

Attribute is the attribute of an item

type CEconAsset

type CEconAsset struct {
	AppID          uint   `json:",string"`
	ContextID      uint64 `json:",string"`
	AssetID        uint64 `json:",string"`
	CurrencyID     uint64 `json:",string"`
	ClassID        uint64 `json:",string"`
	InstanceID     uint64 `json:",string"`
	Amount         uint64 `json:",string"`
	Missing        bool
	MarketHashName string

CEconAsset represents an asset in steam web api

type CEconTradeOffer

type CEconTradeOffer struct {
	TradeOfferID       uint64 `json:",string"`
	OtherAccountID     uint64 `json:"accountid_other"`
	Message            string
	ExpirationTime     uint32             `json:"expiration_time"`
	State              State              `json:"trade_offer_state"`
	ToGive             []*CEconAsset      `json:"items_to_give"`
	ToReceive          []*CEconAsset      `json:"items_to_receive"`
	IsOurs             bool               `json:"is_our_offer"`
	TimeCreated        uint32             `json:"time_created"`
	TimeUpdated        uint32             `json:"time_updated"`
	FromRealTimeTrade  bool               `json:"from_real_time_trade"`
	EscrowEndDate      uint32             `json:"escrow_end_date"`
	ConfirmationMethod ConfirmationMethod `json:"confirmation_method"`
	TradeID            uint64             `json:"tradeid,string"`

CEconTradeOffer represent the to from the steam API

func IEconGetTradeOffer

func IEconGetTradeOffer(apiKey string, tradeOfferID uint64) (
	*CEconTradeOffer, error,

IEconGetTradeOffer retrieves details about a specific tradeoffer

type CEconTradeOffers

type CEconTradeOffers struct {
	Sent     []*CEconTradeOffer `json:"trade_offers_sent"`
	Received []*CEconTradeOffer `json:"trade_offers_received"`

CEconTradeOffers represent the list of different tradeoffers types

func IEconGetTradeOffers

func IEconGetTradeOffers(
	apiKey string,
	getSentOffers bool,
	getReceivedOffers bool,
	getDescriptions bool,
	activeOnly bool,
	historicalOnly bool,
	timeHistoricalCutoff int64,
) (*CEconTradeOffers, error)

IEconGetTradeOffers retrieves a list of tradeoffers

type CommunityVisibilityState

type CommunityVisibilityState int

CommunityVisibilityState contains the visibility of the user

const (
	// Private community visibility state
	Private CommunityVisibilityState = 1
	// FriendsOnly community visibility state
	FriendsOnly CommunityVisibilityState = 2
	// Public community visibility state
	Public CommunityVisibilityState = 3

type ConfirmationMethod

type ConfirmationMethod int

ConfirmationMethod different methods in which a trade offer can be confirmed.

const (
	// ETradeOfferConfirmationMethodInvalid Invalid
	ETradeOfferConfirmationMethodInvalid ConfirmationMethod = 0
	// ETradeOfferConfirmationMethodEmail An email was sent with details on how to confirm the trade offer
	ETradeOfferConfirmationMethodEmail ConfirmationMethod = 1
	// ETradeOfferConfirmationMethodMobileApp The trade offer may be confirmed via the mobile app
	ETradeOfferConfirmationMethodMobileApp ConfirmationMethod = 2

type EquipInfo

type EquipInfo struct {
	Class int
	Slot  int

EquipInfo class and slot of equipment

type Info

type Info struct {
	ClassID        string `json:"classid"`
	IconURL        string `json:"icon_url"`
	MarketHashName string `json:"market_hash_name"`
	Tradable       string
	Marketable     string

Info is the details about the class info

func GetAssetClassInfo

func GetAssetClassInfo(appID, classID uint64, language, apiKey string) (*Info, error)

GetAssetClassInfo returns asset details

type Inventory

type Inventory struct {
	Status        uint
	BackpackSlots int `json:"num_backpack_slots"`
	Items         []Item

Inventory is the inventory of the user as represented in steam

func GetPlayerItems

func GetPlayerItems(steamID uint64, appID uint64, apiKey string) (*Inventory, error)

GetPlayerItems Fetches the player summaries for the given Steam Id.

type Item

type Item struct {
	ID                uint64
	OriginalID        uint64 `json:"original_id"`
	Defindex          uint32
	Level             int
	Quantity          int
	Origin            int
	Untradeable       bool   `json:"flag_cannot_trade,omitempty"`
	Uncraftable       bool   `json:"flag_cannot_craft,omitempty"`
	InventoryToken    uint32 `json:"inventory"`
	Quality           int
	CustomName        string      `json:"custom_name,omitempty"`
	CustomDescription string      `json:"custom_description,omitempty"`
	Attributes        []Attribute `json:",omitempty"`
	Equipped          []EquipInfo `json:",omitempty"`

Item in an inventory

func (*Item) Position

func (i *Item) Position() uint16

Position gets the position of the item in an inventory

type ItemDescription

type ItemDescription struct {
	AppID          uint   `json:"appid"`
	ClassID        uint64 `json:"classid,string"`
	InstanceID     uint64 `json:"instanceid,string"`
	MarketHashName string `json:"market_hash_name"`
	IconURL        string `json:"icon_url"`
	NameColor      string `json:"name_color"`
	Name           string `json:"name"`

ItemDescription represents the details about the items unique w classid instanceid

type ItemRank

type ItemRank struct {
	Level         int
	RequiredScore int `json:"required_score"`
	Name          string

ItemRank is the rank of the item

type ItemRankSet

type ItemRankSet struct {
	Name   string
	Levels []ItemRank

ItemRankSet is the set of the possible ranks

type ItemSet

type ItemSet struct {
	InternalName string `json:"item_set"`
	Name         string
	StoreBundle  string `json:"store_bundle,omitempty"`
	Items        []string
	Attributes   []SchemaItemAttribute `json:",omitempty"`

ItemSet is an item set

type KillEaterScoreType

type KillEaterScoreType struct {
	ID   int    `json:"type"`
	Name string `json:"type_name"`

KillEaterScoreType is the type of kill eater score

type Origin

type Origin struct {
	ID   int `json:"origin"`
	Name string

Origin is an item origin as defined in the Schema.

type ParticleEffect

type ParticleEffect struct {
	System           string
	ID               int
	AttachToRootbone bool   `json:"attach_to_rootbone"`
	Attachment       string `json:",omitempty"`
	Name             string

ParticleEffect is the particle effect

type PersonaState

type PersonaState int

PersonaState is the visibility state

const (
	// Offline persona state is also
	// used when the steam user has set his profile
	// to private.
	Offline PersonaState = iota

	// Online is online
	// Busy is busy
	// Away is away
	// Snooze is sniooze
	// LookingToTrade is looking to trade
	// LookingToPlay is looking ot play

type PlayerBan

type PlayerBan struct {
	SteamID          uint64 `json:"SteamId,string"`
	CommunityBanned  bool
	VACBanned        bool
	EconomyBan       string
	NumberOfVACBans  uint
	DaysSinceLastBan uint
	NumberOfGameBans uint

PlayerBan contains all ban status for community, VAC and economy

func GetPlayerBans

func GetPlayerBans(steamIDs []uint64, apiKey string) ([]PlayerBan, error)

GetPlayerBans takes a list of steamIDs and returns PlayerBan slice

type PlayerSummary

type PlayerSummary struct {
	SteamID                  uint64 `json:",string"`
	CommunityVisibilityState CommunityVisibilityState
	ProfileURL               string

	ProfileState int // Set to 1 if the player has configured the profile.
	PersonaName  string
	LastLogoff   int64
	PersonaState PersonaState

	SmallAvatarURL  string `json:"avatar"`       // 32x32
	MediumAvatarURL string `json:"avatarmedium"` // 64x64
	LargeAvatarURL  string `json:"avatarfull"`   // 184x184

	TimeCreated   int64  `json:",omitempty"`
	RealName      string `json:",omitempty"`
	GameExtraInfo string `json:",omitempty"`

	PrimaryClanID uint64 `json:",string,omitempty"`

PlayerSummary gives an overall state of the user in steam community

func GetPlayerSummaries

func GetPlayerSummaries(ids []uint64, apiKey string) ([]PlayerSummary, error)

GetPlayerSummaries Fetches the player summaries for the given Steam Ids.

type RegionId

type RegionId int
const (
	World RegionId = 255

	USEast RegionId = iota

type Relationship

type Relationship string

Relationship is a type of relationship

const (
	// All is a type of relationship
	All Relationship = "all"
	// Friend is a type of relationship
	Friend Relationship = "friend"

type ResolveVanityURLResponse

type ResolveVanityURLResponse struct {
	Response struct {
		Success int
		SteamID uint64 `json:"steamid,string"`
		Message string

ResolveVanityURLResponse resolves the response from steam

func ResolveVanityURL

func ResolveVanityURL(vanityURL string, apiKey string) (*ResolveVanityURLResponse, error)

ResolveVanityURL should return a response

type Schema

type Schema struct {
	Status                               int
	FullSchemaURL                        string `json:"items_game_url"`
	Qualities                            map[string]int
	QualityNames                         map[string]string
	OriginNames                          []Origin
	Items                                []SchemaItem
	Attributes                           []SchemaAttribute
	ItemSets                             []ItemSet
	AttributeControlledAttachedParticles []ParticleEffect     `json:"attribute_controlled_attached_particles"`
	ItemLevels                           []ItemRankSet        `json:"item_levels"`
	KillEaterScoreTypes                  []KillEaterScoreType `json:"kill_eater_score_types"`

Schema is a game schema

func GetSchema

func GetSchema(appID int, language, APIKey string) (*Schema, error)

GetSchema Fetches the Schema for the given game.

func (*Schema) Item

func (s *Schema) Item(defindex int) *SchemaItem

Item finds an item by its defindex in a Schema.

type SchemaAttribute

type SchemaAttribute struct {
	Name              string
	Defindex          int
	Class             string `json:"attribute_class"`
	MinValue          float64
	MaxValue          float64
	Description       string `json:"description_string,omitempty"`
	DescriptionFormat string `json:"description_format,omitempty"`
	EffectType        string `json:"effect_type"`
	Hidden            bool
	StoredAsInteger   bool `json:"stored_as_integer"`

SchemaAttribute is a schema attribute

type SchemaItem

type SchemaItem struct {
	Name               string
	Defindex           int
	ItemClass          string                `json:"item_class"`
	ItemTypeName       string                `json:"item_type_name"`
	ItemName           string                `json:"item_name"`
	Description        string                `json:"item_description,omitempty"`
	ProperName         bool                  `json:"proper_name"`
	Slot               string                `json:"item_slot"`
	DefaultQuality     int                   `json:"item_quality"`
	InventoryImage     *string               `json:"image_inventory"` // this is null for the "Free Trial Premium Upgrade"
	ImageURL           string                `json:"image_url"`
	ImageURLLarge      string                `json:"image_url_large"`
	DropType           string                `json:"drop_type,omitempty"`
	ItemSet            string                `json:"item_set,omitempty"`
	HolidayRestriction string                `json:"holiday_restriction"`
	MinLevel           int                   `json:"min_ilevel"`
	MaxLevel           int                   `json:"max_ilevel"`
	CraftClass         string                `json:"craft_class,omitempty"`
	Capabilities       map[string]bool       `json:",omitempty"`
	UsedByClasses      []string              `json:"used_by_classes,omitempty"`
	ClassLoadoutSlots  map[string]string     `json:"per_class_loadout_slots,omitempty"`
	Styles             []Style               `json:",omitempty"`
	Attributes         []SchemaItemAttribute `json:",omitempty"`

SchemaItem is a schema description of an Item.

type SchemaItemAttribute

type SchemaItemAttribute struct {
	Name  string
	Class string
	Value float64

SchemaItemAttribute is the schema items attributes

type ServerInfo

type ServerInfo struct {
	Addr string

	// Seems to always be 65534
	// TODO: find out meaning of value
	Gmsindex   uint32
	Message    string
	AppId      uint64
	GameDir    string
	Region     RegionId
	VACSecured bool `json:"secure"`
	LANOnly    bool `json:"lan"`
	GamePort   uint16
	SpecPort   uint16

func GetServerInfo

func GetServerInfo(ip net.IP) ([]ServerInfo, error)

type State

type State uint

State represents the state of the tradeoffer, see constants

const (
	// ETradeOfferStateCreated /!\ non steam status, used to know the TO has been created
	ETradeOfferStateCreated State = 0
	// ETradeOfferStateInvalid Invalid
	ETradeOfferStateInvalid State = 1
	// ETradeOfferStateActive This trade offer has been sent, neither party has acted on it yet.
	ETradeOfferStateActive State = 2
	// ETradeOfferStateAccepted The trade offer was accepted by the recipient and items were exchanged.
	ETradeOfferStateAccepted State = 3
	// ETradeOfferStateCountered The recipient made a counter offer
	ETradeOfferStateCountered State = 4
	// ETradeOfferStateExpired The trade offer was not accepted before the expiration date
	ETradeOfferStateExpired State = 5
	// ETradeOfferStateCanceled The sender cancelled the offer
	ETradeOfferStateCanceled State = 6
	// ETradeOfferStateDeclined The recipient declined the offer
	ETradeOfferStateDeclined State = 7
	// ETradeOfferStateInvalidItems Some of the items in the offer are no longer available
	// (indicated by the missing flag in the output)
	ETradeOfferStateInvalidItems State = 8
	// ETradeOfferStateCreatedNeedsConfirmation The offer hasn't been sent yet and is awaiting email/mobile confirmation. The offer is only visible to the sender.
	ETradeOfferStateCreatedNeedsConfirmation State = 9
	// ETradeOfferStateCanceledBySecondFactor Either party canceled the offer via email/mobile. The offer is visible to both parties, even if the sender canceled it before it was sent.
	ETradeOfferStateCanceledBySecondFactor State = 10
	// ETradeOfferStateInEscrow The trade has been placed on hold. The items involved in the trade have all been removed from both parties' inventories and will be automatically delivered in the future.
	ETradeOfferStateInEscrow State = 11

type SteamApp

type SteamApp struct {
	AppId uint64
	Name  string

func GetAppList

func GetAppList() ([]SteamApp, error)

type SteamFriend

type SteamFriend struct {
	SteamID      uint64 `json:",string"`
	Relationship Relationship
	FriendSince  int64 `json:"friend_since"`

SteamFriend is a relationship between two steam users

func GetFriendsList

func GetFriendsList(steamID uint64, filter Relationship, apiKey string) ([]SteamFriend, error)

GetFriendsList Fetches the friends of the given steam id and returns the result.

It returns nil if the profile is private or if there were no friends found for the given relationship. In either one of both cases, no error is returned.

type SteamMethod

type SteamMethod string

A SteamMethod represents a Steam Web API method.

func NewSteamMethod

func NewSteamMethod(interf, method string, version int) SteamMethod

NewSteamMethod creates a new SteamMethod.

func (SteamMethod) Request

func (s SteamMethod) Request(data url.Values, v interface{}) error

Request makes a request to the Steam Web API with the given url values and stores the result in v.

Returns an error if the return status code was not 200.

type Style

type Style struct {
	Name string

Style is an item style


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL