Skip to content

Unsupported Content-Type header, use application/json 2025-01 #669

@mete89

Description

@mete89

I have a simple graphql which returns Unsupported Content-Type header, use application/json 2025-01 error in 2025-01 although it works fine versions <= 2024-10.

            {
                productVariantsCount {
                  count
                  precision
                }
            }

It works fine when we add an empty object as variable to the graphql to force json usage here:

Shopify.prototype.graphql = function graphql(data, variables) {
  let pathname = '/admin/api';

  if (this.options.apiVersion) {
    pathname += `/${this.options.apiVersion}`;
  }

  pathname += '/graphql.json';

  const uri = { pathname, ...this.baseUrl };
  const json = variables !== undefined && variables !== null;
  const options = {
    agent: this.options.agent,
    body: json ? this.options.stringifyJson({ query: data, variables }) : data,
    headers: {
      ...this.baseHeaders,
      'Content-Type': json ? 'application/json' : 'application/graphql'
    },
    method: 'POST',
    parseJson: this.options.parseJson,
    responseType: 'json',
    timeout: this.options.timeout
  };

Related changelog:

https://shopify.dev/docs/api/release-notes/2025-01

JSON body support: We now provide native support of a HTTP request body as a JSON_body for function external calls. Use this field when the body is in JSON format to reduce function instruction consumption and to ensure the body is formatted in logs. Don't use the JSON_body field together with the body field in the HttpResponse object. If both are provided, then the HttpResponse's body field takes precedence. If the JSON_body field is specified and no Content-Type header is included, then the header will automatically be set to application/json.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions