Created
June 4, 2020 12:24
-
-
Save cgartner-redstage/84ee2c93ce033c06bae606046ab3d7bb to your computer and use it in GitHub Desktop.
Get product info with GraphQL Bigcommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var jsContext = JSON.parse({{jsContext}}); | |
var entities = jsContext.products.map(function (product) { | |
return product.id | |
}); | |
fetch('/graphql', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
'Authorization': 'Bearer {{ settings.storefront_api.token }}' | |
}, | |
body: JSON.stringify({ | |
query: ` | |
query SingleProduct { | |
site { | |
products (entityIds: [`+ entities.toString() +`]) { | |
edges { | |
node { | |
id | |
entityId | |
name | |
width { | |
...DimensionFields | |
} | |
height { | |
...DimensionFields | |
} | |
depth { | |
...DimensionFields | |
} | |
} | |
} | |
} | |
} | |
} | |
fragment DimensionFields on Measurement { | |
value | |
unit | |
} | |
` | |
}), | |
}) | |
.then(res => res.json()) | |
.then(json => console.log(json)); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment