I have a valid access_token and the products/inventory in my Ship Hero account but whenever I’m trying to get the products list using the GraphQL API, I’m getting null in the response.
Below are some screenshots of my account, that will prove that I have inventory in my account
You get the null response because you set the analyze parameter to true. When analyze is true, the response you get is the query’s complexity instead of the actual response. It’s a flag for testing purposes so you can check how many credits the query you built will expend. You need to either set it to false or delete the whole parameter, as when it is not present, it defaults to false.
With that said, I see you are using the product query, which requires you to send an ID or SKU as a parameter for it to return a value.
Suppose you want to get all products and paginate through them. In that case, you can use the products query, which doesn’t necessarily need parameters, and will return an array of all the products it finds in the database associated with the account you are connected to.
@tomasfd okay, I got your point. In your documentation under the products query, it is written to always use analyze:true for better performance and it will leave a good impact on your credits. When I’m trying to access the products query from JacaScript code and I’m using the graphql-request client recommended by in your documentation, I’m getting the following error
{
"message": "There are not enough credits to perform the requested operation, which requires 3001 credits, The max allowed for your account is 2002 credits per operation. : {\"response\":{\"errors\":[{\"code\":30,\"message\":\"There are not enough credits to perform the requested operation, which requires 3001 credits, The max allowed for your account is 2002 credits per operation. \",\"operation\":\"products\",\"request_id\":\"61f7f2967aa87188e3dca778\",\"required_credits\":3001,\"remaining_credits\":2002,\"time_remaining\":\"0\"}],\"data\":{\"products\":null},\"status\":200,\"headers\":{}},\"request\":{\"query\":\"\\n query {\\n products{\\n request_id\\n complexity\\n data{\\n edges {\\n node {\\n id\\n legacy_id\\n account_id\\n name\\n sku\\n barcode\\n country_of_manufacture\\n dimensions {\\n height\\n width\\n length\\n weight\\n }\\n tariff_code\\n kit\\n kit_build\\n no_air\\n final_sale\\n customs_value\\n customs_description\\n not_owned\\n dropship\\n needs_serial_number\\n thumbnail\\n large_thumbnail\\n created_at\\n updated_at\\n product_note\\n virtual\\n ignore_on_invoice\\n ignore_on_customs\\n active\\n warehouse_products {\\n id\\n warehouse_id\\n on_hand\\n available\\n backorder\\n reserve_inventory\\n replenishment_level\\n reorder_amount\\n reorder_level\\n backorder\\n allocated\\n }\\n images {\\n src\\n }\\n tags\\n kit_components {\\n sku\\n quantity\\n }\\n }\\n }\\n }\\n }\\n }\\n \"}}"
}
I have tried to change the access_token many times but still, I’m getting this error, while other queries are working fine like orders
Back to this particular case, the way the query is set up, the cost per product queried is 30 credits. If you don’t set the parameter for the number of products you want in the response, it will default to 100. This is the reason you are getting a cost of 3001.
You can restrict the number of returned nodes can by adding the following parameter to the data field:
In this case, I’m limiting the number of nodes returned to 10, lowering the cost to 300 credits.
The best route to avoid this from happening is to get fewer products per call and use pagination to advance through the whole array. You can find more information about pagination at this link: GraphQL Primer – Developer Resources | ShipHero.