Hey everyone! Dhruv from the engineering team at Product Hunt. The new version for the Product Hunt public API is built using GraphQL. We want you to have a smooth experience while integrating with the API and I'll be here to assist you in any issues that might arise.
Here are some quick tips to get started:
1. To explore the GraphQL interface of the API quickly, you can use the GraphiQL Explorer app.
2. We've published a minimal Node + React App as a starter kit on Github here.
Happy Hacking π»π!
@dhruvparmar I'm trying minimal Node + React App as a starter kit, but on clicking Login with product hunt, it get redirected to /authorize but nothing seems to happen. also there is this POST http://localhost:3001/graphql 404 (Not Found) in console.
@akshay_ashok1 Hey, please make sure to copy `.env.sample` file and rename it to `.env` file in your project root. Also update all `PH_` variables in the `.env` file to appropriate values. I'm guessing there is an issue with the environment variables.
@dhruvparmar Hi Dhruv, Apollo client for iOS or MacOS requires schema.json file of GraphQL server. I tried Apollo CLI to download but was getting 401. Probably missing something. Since this is not user-specific, is it available to download? if yes then please point me to the location. Your help will be much appreciated
@dhruvparmar Hello, how can I get all user following and do not rest against the limit of the API?
For example, I want to see what people which I follow do on PH(upvote something, comment, add/finish goal)
@nikolay_siabrenko you can look up "followers" for a user. check here http://api-v2-docs.producthunt.c...
If you run into rate limit issues try fetching "followers" on a per "user" basis. http://api-v2-docs.producthunt.c...
We do not support subscriptions as of now, so to get a "user"'s activity you would have to regularly poll for the specific data and detect changes in that on your end. For e.g
1. To detect if a user upvoted a new post, you could poll for "votedPosts" list on the "user" object.
2. To detect changes to user's goal, you can poll "goals(userId: idOfUser)" connection with 'NEWEST' filter.
@dhruvparmar Is there a way to upvote using this API? I don't see a mutation for that? Also, what will be the validity for the access_grant_token & access_token?
@dhruvparmar hi, still pretty new on this graphql things, but it seem like no way to filter the records ? like if I want to filter all my goals that complete only ? I can only fetch all and filter locally ?
@imknight hey, you can filter "goals" by using "completed" flag here http://api-v2-docs.producthunt.c...
Setting `completed: true` on the query will result in only completed goals being fetched.
@dhruvparmar the same mutation work on API Explorer and not on local dev, could that my account not grant for write access scope ? but I already apply, will I get a confirmation ?
@dhruvparmar Hey, amazing job on the GraphQL API. Are you guys going to add more fields to the post query? I need the post makers and images also reviews would be great ;)
@ossamaweb@asingh thanks for feedback guys π. We should be able to add those fields to Post query. I'll update here once they are added. Would be good if you could elaborate how you'd be using them in your respective applications?
@dhruvparmar I'm getting "Cannot return null for non-nullable field Collection.coverImage" when attempting to fetch a collection's coverImage. It works fine for Users as that's nullable, but seems like collections have it set to be not nullable where it may actually still return nothing. Any idea on what to do with this one?
@dhruvparmar I wasn't fetching a single collection. I was fetching all collections with the parameter "first: 10" in an attempt to populate a list of collections.
@dhruvparmar Seems like doing a "goals" query keeps returning a 204 (no content) for me. It works fine from the API explorer, but any call to this endpoint from my code succeeds but doesn't return anything. Any idea on what may be up with this?
EDIT: This has now been resolved on the server-side.
@dhruvparmar I see some planned updates to APIs here and see recent changes on github. Will the docs be updated asap or do we need to keep an eye here and on github?
@wayfarerish hey, any updates to the GraphQL interface of the API will always reflect in the reference here http://api-v2-docs.producthunt.c...
Unfortunately we don't have a change-log yet so we've decided to publish those updates here as well for the Makers festival participants.
@dhruvparmar Facing this error on POST request Use the access grant code you received through the redirect to request an access token
error:"invalid_grant"
error_description:"The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."
@yhdesai hey, The "invalid_grant" issue is most likely due to an invalid `code` being used to request the access token.
Regarding the starter kit, the get access token part is executed here https://github.com/producthunt/p... once the user authorizes your application.
Incase you are looking to build a client only application and do not need users to authorize it you can check out this codesandbox https://codesandbox.io/s/phapi20... as well.
@dhruvparmar@yhdesai I was facing this issue earlier too, which I resolved through ensuring that the redirect_uri in both the authorise and token calls matched.
@dhruvparmar@yhdesai@jpeguin1 I am trying the same endpoint using v2 and it still throws this error. The code and redirect_uri are correct. What might be wrong?
@nikolay_siabrenko@dhruvparmar Great job! Would it be possible to provide votes as query? The use case I am thinking of is to trigger an action when a post reaches a certain amount of upvotes. II do not want to track the number of upvotes for a specific post but for all posts - for example show post on a webpage once it reaches 100 upvotes.
@janzikan hey, we do not plan on exposing "votes" on the root query, as "votes" should always be fetched in the context of a Votable type. For your use case I'd suggest going with something like this
1. Fetch posts ordered by VOTES everyday
2. Filter out posts which could hit the threshold (100 in this case) and trigger polling the "post(id: postId)" field for them.
I know this is not ideal, but probably something that could work. Don't worry about the number of requests as we can increase your rate limit quotas if you start getting blocked by them.
@dhruvparmar Better solution would be to be able to filter posts that have upvotes count greater than X and to order them by VOTES but in descending order. Are you planning to implement option for ordering so we choose whether the results should be ordered in ascending or descending order? Are you planning to implement filtering for the queries?
@janzikan the VOTES option sorts posts in descending order of votes count currently. We don't have plans to add filtering for the votes query as of now.
Regarding ability to define the sort order, we'll try to incorporate this into the API.
I'll share an update here once it's implemented.
@jpeguin1 We don't have that as of now, but are considering opening it up via `goals` field on the root query. I'll keep you updated here if it's added.
@dhruvparmar Hi, I've got a quick question about mutations. When attempting to mark a goal as complete, I only get returned {"data":{"goalMarkAsComplete":{"node":null}}}
Is this intentional? As it doesn't actually seem to perform the action. Here is my request:
mutation {
goalMarkAsComplete(input: {clientMutationId: "\(clientId)", goalId: \(goalId)}) {
node {
id, completedAt, createdAt, title, user {
name, id, profileImage, username
}
}
}
}
And what is the clientMutationId? Is it just a random String or the client ID that's retrieved when authenticating?
EDIT: After looking at the error, it's an access_denied error, any way to resolve this?
@dhruvparmar Hello, find a bug in pageInfo, if you use query without first param, hasNextPage always false, but by default - first: 20
{
viewer {
user {
following(after: "", first: 20) {
totalCount
pageInfo {
endCursor,
hasNextPage
}
edges {
cursor
node {
id
}
}
}
}
}
}
@nikolay_siabrenko hey, thanks for reporting the issue, I can confirm it's a bug and we'll be working on fixing it. Unfortunately the issue exists in one of the 3rd party packages we use internally so it might be a while before the fix is in.
I'd suggest going with always including `first: 20` in the connection variables for now.
@dhruvparmar Hey, I've got a quick question regarding the API - So a simple body param to fetch posts would look like "query": "query { posts(first: 1) { edges { node { id, name } } } }", but what would one for fetching something more nested like the posts in a collection look like? And in general where can I find this documented?
EDIT: I've now figured it out. For anyone curious: Start with "collection(id: idOfTheCollection) {... which should return all posts in the collection.
YourStack