I want to fetch products data with GraphQL on JS.
I tried below examples from tutorial and I got network error happens.
Could you tell me what is the reason?
import { GraphQLClient} from ‘graphql-request’
async function main() {
const endpoint = ‘https://public-api.shiphero.com/graphql’
const graphQLClient = new GraphQLClient(endpoint, {
headers: {
authorization: ‘Bearer TOKEN’,
},
})
const query = /* GraphQL */ { products { request_id complexity data(first: 10) { edges { node { id sku } } } } }
const data = await graphQLClient.request(query)
console.log(JSON.stringify(data, undefined, 2))
}
Hey @TopCodeBeast,
Thanks for reaching out!
Going to look into this now. Does that by chance return a request id at all?
Please let me know if you have any questions or concerns!
Best,
RayanP
I think the problem maybe Token related.
I just change Token instead of ‘Bearer Token’
headers: {
authorization: ‘Bearer TOKEN’,
},
Error is like this:
browser-ponyfill.js:480 Uncaught (in promise) TypeError: Network request failed
at xhr.onerror (browser-ponyfill.js:480:1)
Hey @TopCodeBeast,
We’re not familiar with how JS handles errors, would it be possible for you to share the actual response you got from us, along with the request id?
Please let me know if you have any questions
Can you show me one of your developers contact?
Hey @TopCodeBeast,
Happy Friday and thanks for hanging in there.
I believe there is a slight misunderstanding. The Developer Community is a forum where our clients developers can ask, answer, and search for questions. Unfortunately, there are no ShipHero Developers here, just our Public API Specialists that maintain this forum.
If you can send us the response and request id, we’ll do our best to troubleshoot your issue!
Please let me know if you have any questions or concerns.
Best,
RayanP
Can you try to make a guide for fetch Data in JS?
I found the reason,
It is making Cors error on my local.
I tried on postman and it is working well.
const shipHeroApi = Axios.create({
baseURL: ‘https://public-api.shiphero.com’,
headers: {
‘Accept’: ‘/’,
‘authorization’:
‘Bearer MY_Token’,
},
data: {
‘query’: { products { data(first: 10) { edges { node { id sku } } } } }
,
},
});
1 Like
When I fetch products on postman, it is nothing to show.
The products only show that I posted on Ship Hero hosting?
Hey @TopCodeBeast,
Would you mind sending the request id for that call?
Please let me know if you have any questions or concerns!
Best,
RayanP
{
products {
request_id,
data(first: 10) {
edges {
node {
id
sku
}
}
}
}
}
This is query and my request Id is “637dc7dd2a2f39d276f69ff5”
This is result
"data": {
"products": {
"request_id": "637dc7dd2a2f39d276f69ff5",
"data": {
"edges": []
}
}
},
"extensions": {
"throttling": {
"estimated_complexity": 11,
"cost": 1,
"cost_detail": {
"products": {
"items_count": 0,
"cost": 1,
"total_cost": 1,
"fields": {}
}
},
"user_quota": {
"credits_remaining": 2001,
"max_available": 2002,
"increment_rate": 30
}
}
}
1 Like