Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any documentation on how to make a request? #86

Closed
onnttf opened this issue Jul 11, 2024 · 3 comments
Closed

Is there any documentation on how to make a request? #86

onnttf opened this issue Jul 11, 2024 · 3 comments

Comments

@onnttf
Copy link

onnttf commented Jul 11, 2024

Hello, I want to get the release list of a repo. Is there any relevant document?

Here is my code:

tokenProvider := auth.NewTokenProvider(
	// to create an authenticated provider, uncomment the below line and pass in your token
	// auth.WithTokenAuthentication("ghp_your_token"),
	auth.WithUserAgent("octokit/go-sdk.example-functions"),
)
adapter, err := kiotaHttp.NewNetHttpRequestAdapter(tokenProvider)
if err != nil {
	log.Fatalf("Error creating request adapter: %v", err)
}

var p *int32 = new(int32)
*p = 1

var p1 *int32 = new(int32)
*p1 = 1

resp, err := repos.
	NewItemItemReleasesRequestBuilder("https://github.com/octokit/go-sdk", adapter).
	Get(context.Background(), &abstractions.RequestConfiguration[repos.ItemItemReleasesRequestBuilderGetQueryParameters]{
		QueryParameters: &repos.ItemItemReleasesRequestBuilderGetQueryParameters{
			Page:     p,
			Per_page: p1,
		},
	})
if err != nil {
	panic(err)
}
fmt.Print(resp)

Here is the error message:

panic: content type application/json does not have a factory registered to be parsed

How should I modify it?

Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@kfcampbell
Copy link
Member

kfcampbell commented Jul 15, 2024

It's definitely a bit confusing, since our OpenAPI spec isn't always perfectly normalized and we have a whole bunch of models to use, and there's a lot of Kiota helpers generated as well.

Here's the approach I've found helpful (and maybe we should add this to the docs somewhere):

        client, err := pkg.NewApiClient(
		pkg.WithUserAgent("my-user-agent"),
		pkg.WithRequestTimeout(5*time.Second),
		pkg.WithBaseUrl("https://api.github.com"),
		pkg.WithTokenAuthentication(os.Getenv("GITHUB_TOKEN")),
	)

	if err != nil {
		log.Fatalf("error creating client: %v", err)
	}

	releases, err := client.Repos().ByOwnerId("octokit").ByRepoId("go-sdk").Releases().Get(context.Background(), nil)
	if err != nil {
		log.Fatalf("error getting releases: %v", err)
	}
	log.Printf("Releases:\n")
	for _, release := range releases {
		log.Printf("Tag: %v\n", *release.GetTagName())
		log.Printf("Notes: %v\n", *release.GetBody())
	}

I hope that helps!

@onnttf
Copy link
Author

onnttf commented Jul 16, 2024

Thank you very much for your help, it solved my problem.

@onnttf onnttf closed this as completed Jul 16, 2024
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants