Skip to content

Latest commit

 

History

History
57 lines (45 loc) · 1.99 KB

README.md

File metadata and controls

57 lines (45 loc) · 1.99 KB

MyTarget API SDK GO (Unofficial)

Build Status codecov Go Report Card Release License

Description

Unofficial MyTarget API Client for Golang

API documentation

https://target.my.com/help/partners/management_api/ru

https://target.my.com/adv/api-marketing/doc/stat-v2

https://target.my.com/help/partners/reporting_api_statistics/ru

Download

go get -u github.com/kachit/mytarget-sdk-go

Usage

package main

import (
    "fmt"
    "net/http"
    mytarget_sdk "github.com/kachit/mytarget-sdk-go"
    mytarget_sdk_marketing "github.com/kachit/mytarget-sdk-go/marketing"
)

func yourFuncName(){ 
    accessToken := "Access token"
    client := mytarget_sdk.NewClientFromCredentials(accessToken, &http.Client{})

    filter := &mytarget_sdk_marketing.StatsFilter{}
    filter.DateFrom = time.Date(2020, time.Month(9), 1, 0, 0, 0, 0, time.UTC)
    filter.DateTo = time.Date(2020, time.Month(9), 2, 0, 0, 0, 0, time.UTC)
    response, err := client.Marketing().Statistics().GetCampaignStatsDaily(filter)

    if response.IsSuccess() {
        var stats marketing.StatsCollection
        response.Unmarshal(&stats)
        fmt.Println(stats.Items[0].Id)
        fmt.Println(stats.Total.Base.Clicks)
    } else {
        errorRes, _ := response.GetError()
        fmt.Println(errorRes.Error.Code)
        fmt.Println(errorRes.Error.Message)
    }

    fmt.Println(err)
}