try {
var uri = Uri.parse("https://nextsavy-demo.myshopify.com/api/2023-07/graphql.json");
var response = await http
.post(uri, body: {"query": "{
"query": "query GetCart($cartId: ID!) { cart(id: $cartId) { id lines(first: 10) { edges { node { id quantity } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } totalTaxAmount { amount currencyCode } totalDutyAmount { amount currencyCode } } buyerIdentity { email phone customer { id } countryCode deliveryAddressPreferences { ... on MailingAddress { address1 address2 city provinceCode countryCodeV2 zip } } } } }",
"operationName": "GetCart",
"variables": {
"cartId": "gid://shopify/Cart/c1-007280228acabc5803619ad*********"
}
}"}, headers: {
"Content-Type": "application/json; charset=UTF-8",
"X-Shopify-Storefront-Access-Token": token
})
.timeout(const Duration(seconds: timeOutDuration));
print(response.statusCode);
if (response.statusCode >= 200 && response.statusCode < 300) {
return response.body;
} else {
_handleResponse(response);
}
} on SocketException {
throw FetchDataException('No internet connection');
} on TimeoutException {
throw ApiNotRespondingException('Api not responding');
}
i use http package in flutter for make api request for getting cart using store front api with graphQl.
i pass query in body parameter.
this is work well in postman and get response. but when i implement in my flutter app it dosen’t work.
i got response “Bad request , error code 400”,