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 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 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 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?
@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 Hey Dhruv. Will you guys support stuff like upvoting, commenting, updating user information, etc. through API v2, or is this Makers Festival only focused on maker goals?
@evrimfeyyaz Hey, there are no plans to add upvoting or commenting as of now. We would be adding updating user information at a later stage. For now we are focusing on adding write functions related to maker goals.
@evrimfeyyaz no since write capabilities in both the versions differ, you would not be able to use v1 endpoints with a v2 application. Also we will soon drop support for v1 API so would be better to build with v2.
@dhruvparmar I would really like to use v2, but unfortunately it is very limited for the idea I had. If you are dropping support for v1 without porting the full functionality to v2, does that mean that many of the apps that were built on v1 will stop working with no way to rewrite them in v2?
@evrimfeyyaz we would definitely give a time buffer for developers to migrate apps to v2 before dropping support for v1. Also we might consider adding some of v1's write capabilities depending on the use case.
As for the Makers festival scope, all apps need to be using v2 API and we wouldn't be adding commenting or upvoting on posts for now.
@dhruvparmar
While trying to retrieve list of product hunt 'Posts' all the 'media' objects are coming as null even though the products have videos or images or both.
More Details :--
Here is the query which I fire.
Query : To retrieve posts order by votes.
{
posts (order: VOTES) {
edges{
node{
id,
name,
media{
type,
videoUrl
}
}
}
}
}
Result : Trimmed part the the corresponding response.
{
"data": {
"posts": {
"edges": [
{
{
"node": {
"id": "76",
"name": "Slack",
"media": [
{
"type": "video",
"videoUrl": null
},
{
"type": "image",
"videoUrl": null
},
{
"type": "image",
"videoUrl": null
},
{
"type": "image",
"videoUrl": null
},
{
"type": "image",
....
.
.
.
.
@vaibhav_soulskill hey, the "videoUrl" specifically only fetches URL for the video if present. Can you try adding "url" field to the "media" object as well? That should give you links to images for all media items.
I've tried running the above query and seems there is a bug with "videoUrl" generation in the API. We'll try and patch it up as soon as possible.
@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.
@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 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 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 Thanks. I'll figure something out. I see that the order of media in the API is different than that on the website. is that bug or website uses some type of sorting?
@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 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.
@amitchambial hey, we've just released some fixes to the API. could you retry the same mutation?
Incase the issue still persists, please write to us at hello@producthunt.com with your API Key & the input you are using for the mutation.
YourStack