Metafields Date and time from api received different than in product

Hello everyone, I entered a metafield of type date and time in the product, but when I use the API to retrieve it, it returns a different value (field time_start). I can’t figure out where the issue is.
image


This is my code:


const productId = ""; 
const storeUrl = "https://your-store-name.myshopify.com/api/2021-07/graphql.json";  

const accessToken = "your-access-token";  


var productQuery = `
  query {
    product(id: "${productId}") {
      id
      title
      descriptionHtml
      featuredImage {
        src
      }
      metafields(identifiers: [
        {namespace: "custom", key: "url_link_button"},
        {namespace: "custom", key: "short_description"},
        {namespace: "custom", key: "time_start"},
        {namespace: "custom", key: "time_end"}
      ]) {
        namespace
        key
        value
      }
    }
  }
`;

fetch(storeUrl, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Shopify-Storefront-Access-Token': accessToken
  },
  body: JSON.stringify({ query: productQuery })
})
  .then(response => response.json())
  .then(data => {
    console.log("Product Information:", data);
  })
  .catch(error => {
    console.error("Error fetching product data:", error);
  });

Thank you!

So the value is different on the product page vs when you query it from your app? If you run this query in the GraphiQL app, are you seeing the same thing (wrong value) appearing? Is the time end metafield appearing okay?

Yes, the time_start I get from the GraphiQL API doesn’t match the time_start I enter in the metafield; I don’t know why either.



here is my code

const productQuery = `
  query {
    product(id: "gid://shopify/Product/10017276461348") {
      id
      title
      descriptionHtml
      featuredImage {
        src
      }
      metafields(identifiers: [
        {namespace: "custom", key: "url_link_button"},
        {namespace: "custom", key: "short_description"},
        {namespace: "custom", key: "time_start"},
        {namespace: "custom", key: "time_end"}
      ]) {
        namespace
        key
        value
      }
    }
  }
`;

fetch('https://royalmotor.com.au/api/2023-01/graphql.json', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Shopify-Storefront-Access-Token': 'mytoken'
  },
  body: JSON.stringify({ query: productQuery })
})
  .then(response => response.json())
  .then(data => {
    console.log(data);
    // You can process the response here, such as adjusting time_start or time_end if necessary
  })
  .catch(error => {
    console.error('Error fetching product data:', error);
  });

Could there be something related to timezones happening here?

yes; the api return result will be in local timezone; is there any way i can get the exact time value entered in the meta field regardless of timezone

Could you try storing it as a text based metafield instead?