Skip to content

cannot unmarshal object into Go struct field GroupPackage.tags of type string

Created by: Quanalogy

with the following code running towards gitlab.com:

import (
	"fmt"
	"github.com/xanzy/go-gitlab"
	"log"
	"os"
)


client, err := gitlab.NewClient(os.Getenv("GITLAB_READ_API_TOKEN"))

if err != nil {
        log.Fatalf("Failed to create client: %v", err)
}

var listOptions = gitlab.ListOptions{
	Page:    1,
	PerPage: 100,
}
var groupOptions = gitlab.ListGroupPackagesOptions{
	ListOptions:      listOptions,
	ExcludeSubGroups: gitlab.Bool(false),
	PackageType:      gitlab.String("nuget"),
}

packages, response, err := client.Packages.ListGroupPackages("YOUR_GROUP_ID", &groupOptions)

I get the error:

Failed call to group endpoint with error: 'json: cannot unmarshal object into Go struct field GroupPackage.tags of type string'

I guess this is due to that our nuget packages contains tags. I've used curl to get the response and found one with many tags, hopefully that is some data to test on:

command to get data:

curl --silent --header "PRIVATE-TOKEN: $GITLAB_READ_API_TOKEN" "https://gitlab.com/api/v4/groups/YOUR_GROUP_ID_HERE/packages?exclude_subgroups=false&package_type=nuget&per_page=100&page=1" | jq '.[].tags'

and relevant data from me with IDs replaces with 1 and 2, for having valid data.

...
[
  {
    "id": 1,
    "package_id": 2,
    "name": "convention",
    "created_at": "2021-05-07T11:47:23.118Z",
    "updated_at": "2021-05-07T11:47:23.118Z"
  },
  {
    "id": 1,
    "package_id": 2,
    "name": "package",
    "created_at": "2021-05-07T11:47:23.118Z",
    "updated_at": "2021-05-07T11:47:23.118Z"
  },
  {
    "id": 1,
    "package_id": 2,
    "name": "build",
    "created_at": "2021-05-07T11:47:23.118Z",
    "updated_at": "2021-05-07T11:47:23.118Z"
  },
  {
    "id": 1,
    "package_id": 2,
    "name": "Output",
    "created_at": "2021-05-07T11:47:23.118Z",
    "updated_at": "2021-05-07T11:47:23.118Z"
  },
  {
    "id": 1,
    "package_id": 2,
    "name": "Copy",
    "created_at": "2021-05-07T11:47:23.118Z",
    "updated_at": "2021-05-07T11:47:23.118Z"
  },
  {
    "id": 1,
    "package_id": 2,
    "name": "Targets",
    "created_at": "2021-05-07T11:47:23.118Z",
    "updated_at": "2021-05-07T11:47:23.118Z"
  },
  {
    "id": 1,
    "package_id": 2,
    "name": "Nuget",
    "created_at": "2021-05-07T11:47:23.118Z",
    "updated_at": "2021-05-07T11:47:23.118Z"
  }
]
...

It also seems like response.TotalPages is always 0.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information