Git Product home page Git Product logo

asc-go's Introduction

asc-go

PkgGoDev Test Status codecov

asc-go is a Go client library for accessing Apple's App Store Connect API.

Usage

This project uses Go Modules. It requires Go 1.16 or higher.

import "github.com/cidertool/asc-go/asc"

Construct a new App Store Connect client, then use the various services on the client to access different parts of the App Store Connect API. For example:

client := asc.NewClient(nil)

// list all apps with the bundle ID "com.sky.MyApp"
apps, _, err := client.Apps.ListApps(&asc.ListAppsQuery{
    FilterBundleID: []string{"com.sky.MyApp"},
})

The client is divided into logical chunks closely corresponding to the layout and structure of Apple's own documentation at https://developer.apple.com/documentation/appstoreconnectapi.

For more sample code snippets, head over to the examples directory.

Authentication

You may find that the code snippet above will always fail due to a lack of authorization. The App Store Connect API has no methods that allow for unauthorized requests. To make it easy to authenticate with App Store Connect, the asc-go library offers a solution for signing and rotating JSON Web Tokens automatically. For example, the above snippet could be made to look a little more like this:

import (
    "os"
    "time"

    "github.com/cidertool/asc-go/asc"
)

func main() {
    // Key ID for the given private key, described in App Store Connect
    keyID := "...."
    // Issuer ID for the App Store Connect team
    issuerID := "...."
    // A duration value for the lifetime of a token. App Store Connect does not accept a token with a lifetime of longer than 20 minutes
    expiryDuration = 20*time.Minute
    // The bytes of the PKCS#8 private key created on App Store Connect. Keep this key safe as you can only download it once.
    privateKey = os.ReadFile("path/to/key")

    auth, err = asc.NewTokenConfig(keyID, issuerID, expiryDuration, privateKey)
    if err != nil {
        return nil, err
    }
    client := asc.NewClient(auth.Client())

    // list all apps with the bundle ID "com.sky.MyApp" in the authenticated user's team
    apps, _, err := client.Apps.ListApps(&asc.ListAppsQuery{
        FilterBundleID: []string{"com.sky.MyApp"},
    })
}

The authenticated client created here will automatically regenerate the token if it expires. Also note that all App Store Connect APIs are scoped to the credentials of the pre-configured key, so you can't use this API to make queries against the entire App Store. For more information on creating the necessary credentials for the App Store Connect API, see the documentation at https://developer.apple.com/documentation/appstoreconnectapi/creating_api_keys_for_app_store_connect_api.

Rate Limiting

Apple imposes a rate limit on all API clients. The returned Response.Rate value contains the rate limit information from the most recent API call. If the API produces a rate limit error, it will be identifiable as an ErrorResponse with an error code of 429.

Learn more about rate limiting at https://developer.apple.com/documentation/appstoreconnectapi/identifying_rate_limits.

Pagination

All requests for resource collections (apps, builds, beta groups, etc.) support pagination. Responses for paginated resources will contain a Links property of type PagedDocumentLinks, with Reference URLs for first, next, and self. A Reference can have its cursor extracted with the Cursor() method, and that can be passed to a query param using its Cursor field. You can also find more information about the per-page limit and total count of resources in the response's Meta field of type PagingInformation.

auth, _ = asc.NewTokenConfig(keyID, issuerID, expiryDuration, privateKey)
client := asc.NewClient(auth.Client())

opt := &asc.ListAppsQuery{
    FilterBundleID: []string{"com.sky.MyApp"},
}

var allApps []asc.App
for {
    apps, _, err := apps, _, err := client.Apps.ListApps(opt)
	if err != nil {
		return err
	}
	allApps = append(allApps, apps.Data...)
    if apps.Links.Next == nil {
        break
    }
    cursor := apps.Links.Next.Cursor()
    if cursor == "" {
        break
    }
    opt.Cursor = cursor
}

For complete usage of asc-go, see the full package docs.

Contributing

This project's primary goal is to cover the entire API surface exposed by the official App Store Connect API. Otherwise, it's being developed to aid in internal application development by the authors. Therefore, until the package's version stabilizes with v1, there isn't a strong roadmap beyond those stated goals. However, contributions are always welcome. If you want to get involved or you just want to offer feedback, please see CONTRIBUTING.md for details.

License

This library is licensed under the GNU General Public License v3.0 or later

See COPYING to see the full text.

asc-go's People

Contributors

aaronsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

asc-go's Issues

Support Go 1.16

Is your feature request related to a problem? Please describe.
Go 1.16 went stable a couple of weeks ago. It comes with an improved IO module, faster build-times, and Apple M1 support that will make an impact in Cider.

Describe the solution you'd like
Support for Go 1.16 to support Cider running natively on Apple M1, etc.

Support ASC API v1.4

Apple just released a new version of the App Store Connect API. The wrapper should be updated to support it.

Sometimes report “401 NOT_AUTHORIZED ” error

Sometimes report the error:

401 NOT_AUTHORIZED – Authentication credentials are missing or invalid.\n\tProvide a properly configured and signed bearer token, and make sure that it has not expired.

Not always this error, just sometimes!!!

EnableCapability 405 Error

Code:

resp, _, err := c.client.Provisioning.EnableCapability(ctx, capabilityType, []asc.CapabilitySetting{}, bundleID)

Response Error:

PATCH https://api.appstoreconnect.apple.com/v1/bundleIdCapabilities: 405
* 405 METHOD_NOT_ALLOWED – The request method is not valid for the resource path.
        The request method used for this request is not valid for the resource path. Please consult the documentation.

The apple api documentation says Post method,asc-go why is patch method?

https://developer.apple.com/documentation/appstoreconnectapi/enable_a_capability

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.