API Support

Dhruv Parmar
127 replies
Facing any issues with the API? Share them here

Replies

Dhruv Parmar
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 💻🚀!
Akshay Ashok
@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.
Dhruv Parmar
@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.
Sam Ben
@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 ;)
Arj Singh
@dhruvparmar @ossamaweb Yeah I agree. A link to product videos would be handy too. Hope we can get access to this.
Dhruv Parmar
@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?
Yash Desai
@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."
Yash Desai
@dhruvparmar the starter kit seems to be only for the authorize part, can you please add a get access token sample?
Dhruv Parmar
@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.
JPEGuin
@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.
Vaibhav Deep
@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?
JPEGuin
@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.
JPEGuin
@dhruvparmar Is there a way to see all maker goals (not just your own ones)? And is there also. way to see goals that are a part of spaces?
Dhruv Parmar
@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.
Arjun
@dhruvparmar Are these the only allowed mutations? GoalMarkAsCompleteInput GoalMarkAsIncompleteInput GoalUpdateInput What about creating a goal?
Dhruv Parmar
@arjunz Yes, those are the allowed mutations for now. We are working on adding "GoalCreate". I will update you here once it's added.
Arjun
@dhruvparmar Cool thanks. It doesn't make sense to build an app if it only supported marking goals as done :D
Dhruv Parmar
API Update: We've added support to fetch "makers" & "media" for each Post item. Check out http://api-v2-docs.producthunt.c... cc @ossamaweb @asingh2
JPEGuin
@ossamaweb @asingh2 @dhruvparmar Awesome, is this also reflected in the API explorer?
JPEGuin
@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?
Dhruv Parmar
@jpeguin1 that is most likely a bug in the API, do you mind sharing the ID of the collection you are fetching?
JPEGuin
@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.
Dhruv Parmar
@jpeguin1 We've put in a fix for the issue. coverImage should return `null` instead of failing on CollectionType.
Flex.io
Hey @dhruvparmar -- Great to see the v2 starter kit and materials. We're working with python, and are trying to get a basic example up and running with the v2 api using graphql. Question: here's a v1 implementation that queries the posts; what would this look like using the v2 api? import requests auth_token = '' url = 'https://api.producthunt.com/v1/p...' headers = { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + auth_token, 'Host': 'api.producthunt.com' } data = {} response = requests.get(url, headers=headers, data=data)
Dhruv Parmar
@flexiodata thanks for the feedback. these are things that would change for you when querying the v2 API. url = 'https://api.producthunt.com/v2/a...' request_method = 'POST' data = graphql query here I would suggest using a graphql client for python for e.g this one https://github.com/prisma/python... result = client.execute(''' { posts { edges { node { id name tagline } } } } ''') The above query should get you top 20 posts for today on Product Hunt.
Flex.io
Excellent, thanks @dhruvparmar - we're up and running. ... For posterity, here's a complete example should anyone else out there need this (this query will return a list of posts with the id, name, and tagline) import requests import json auth_token = '' url = 'https://api.producthunt.com/v2/a...' headers = { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + auth_token, 'Host': 'api.producthunt.com' } data = { "query": ''' query { posts { edges { node { id name tagline } } } }''' } response = requests.post(url, data=json.dumps(data), headers=headers) content = response.json()
Sam Ben
@dhruvparmar Thanks for adding makers and media. Any plans on adding reviews query?
Dhruv Parmar
@ossamaweb we are currently working on internal changes to reviews. They will be added to the API post that.
vasanth
@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?
Dhruv Parmar
@vsnthv Currently we don't allow upvotes via the API. The access_token is long lived(never expires) and access_grant_token expires in 20m.
Dhruv Parmar
API Update: We've added support to fetch "goals" & "goal(id: goalId)" to the API. Check out http://api-v2-docs.producthunt.c... cc @jpeguin1
JPEGuin
@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.
Prashant Nigam
@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
Dhruv Parmar
@prashantbuddy hey 👋, we've added schema.json & schema.graphql files to the API repository here. Hope this helps https://github.com/producthunt/p... https://github.com/producthunt/p...
Roy Shao
@dhruvparmar Can we have add goal functionality expose via mutation? I want to be able to create a goal on behave of a user.
Dhruv Parmar
@roy_shao we are currently working on additional write functions including "GoalCreate" and will publish update here once it's added.
JPEGuin
@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?
JPEGuin
@producthunt @dhruvparmar Thanks, done it now. Also, I was wondering on when goal creation support will be coming?
Rishi
@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?
Dhruv Parmar
@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.
Sam Ben
@dhruvparmar Is there a way to know which images are GIFs and which are static from media field?
Sam Ben
@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?
Rishi
@dhruvparmar Hey few questions: 1/ I'm guessing there will be an update to available API endpoints where once can create a "goal" on behalf of a user and view all goals for a user, right? 2/ How do we get Projects and Spaces a user is associated with? Don't see that in User object. 3/What is the significance of 'isMaker' flag in User object? I'm getting false for my profile even though I'm part of Makers on PH 4/ Would updates to Goal/s API include ability to comment on a goal and ability to "cheer". Thanks again :)
Dhruv Parmar
@wayfarerish will try to answer point by point 1. Yes there will be update published here once `GoalCreate` mutation is supported. You can view all goals of a user already by using `userId` filter here http://api-v2-docs.producthunt.c... 2. Currently you can only fetch those for the logged in/authenticated user i.e 'viewer'. Check here for details http://api-v2-docs.producthunt.c... 3. 'isMaker' represents whether the User has been added as a maker for any of the posts on ProductHunt. I think the naming is confusing and we'll probably change the field name soon. 4. As of now ability to comment on a goal and ability to "cheer" are not part of the API plans. We might consider exposing those later on. Again there will be an update published here regarding same.
Raghuv Adhepalli
Hi @dhruvparmar. Can we have the youtube url string exposed in "Post" object for all posts that have a youtube video? Thanks !!
Knight 
@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 ?
Dhruv Parmar
@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.
Knight 
@dhruvparmar Got it , i use Viewer to check, is a bit funny, when checking own goal cannot filter by using completed flag