bold-commerce / go-shopify

Go client for the Shopify API
MIT License
318 stars 251 forks source link

Access scopes response err "Not Found" #290

Closed wcig closed 3 months ago

wcig commented 3 months ago

Following is my code:

package api

import (
    "context"
    "encoding/json"
    "fmt"
    "log"
    "testing"

    goshopify "github.com/bold-commerce/go-shopify/v4"
)

func TestQuickStart(t *testing.T) {
    var (
        app     = goshopify.App{}
        shop    = "xxx.myshopify.com"
        token   = "xxx"
        version = "2024-04"
        ctx     = context.Background()
    )

    client, err := goshopify.NewClient(app, shop, token, goshopify.WithVersion(version))
    if err != nil {
        log.Fatal(err)
    }
    _ = client

    scopes, err := client.AccessScopes.List(ctx, nil)
    if err != nil {
        log.Fatal(err) // Not Found
    }
    fmt.Println(toJsonStr(scopes, true))
}

func toJsonStr(v interface{}, p bool) string {
    var (
        data []byte
        err  error
    )
    if p {
        data, err = json.MarshalIndent(v, "", "\t")
    } else {
        data, err = json.Marshal(v)
    }
    if err != nil {
        log.Fatal(err)
    }
    return string(data)
}

I have checked the problem is the request url:

So when request resource is AccessScope, the url does not need to spliced with the version.

pnmcosta commented 3 months ago

I can confirm this is an issue for me too, I'm looking to find out the existing scopes for a missing one we're introducing and getting 404.

I'm going to fork the repo and quickly test with the correct URL

pnmcosta commented 3 months ago

Done, PR https://github.com/bold-commerce/go-shopify/pull/291 fixes it.

In the meantime feel free to use my fork, temporarily add:

replace github.com/bold-commerce/go-shopify/v4 => github.com/pnmcosta/go-shopify/v4 v4.0.0-20240523175202-128fc917c7f2

to the bottom of your project's go.mod file