javascriptjsonpostmanbigcommerce

JSON neglect { when POST


I need to POST a script by using BigCommerce API. Here is the body

{
  "name": "string",
  "description": "string",
  "html": "string",
  "src": "(function (sCDN, sCDNProject, sCDNWorkspace, sCDNVers) {
    if (
      window.localStorage !== null &&
      typeof window.localStorage === 'object' &&
      typeof window.localStorage.getItem === 'function' &&
      window.sessionStorage !== null &&
      typeof window.sessionStorage === 'object' &&
      typeof window.sessionStorage.getItem === 'function'
    ) {
      sCDNVers =
        window.sessionStorage.getItem('wx_preview_version') ||
        window.localStorage.getItem('wx_preview_version') ||
        sCDNVers;
    }
    window.x= window.x|| {};
    window.x.config = window.x.config || {};
    window.x.config.frontend = window.x.config.frontend || {};
    window.x.config.frontend.cdnhost =
      sCDN + '/get/' + sCDNWorkspace + '/web/' + sCDNVers + '/';
    window.x.config.frontend.vers = sCDNVers;
    window.x.config.frontend.env = sCDNWorkspace;
    window.x.config.frontend.project = sCDNProject;
    window._wx = window._wx || [];
    var f = document.getElementsByTagName('script')[0];
    var j = document.createElement('script');
    j.async = true;
    j.src = window.x.config.frontend.cdnhost + 'sss.js';
    f.parentNode.insertBefore(j, f);
  })(
    'https://xxxx.x-x-x.mybigcommerce.com',
    'x-test-env',
    'live',
    '_'
  );",
  "auto_uninstall": true,
  "load_method": "default",
  "location": "head",
  "visibility": "storefront",
  "kind": "src",
  "api_client_id": "string",
  "consent_category": "essential",
  "enabled": true,
  "channel_id": 1
}

but it returned

{ "status": 400, "title": "Input is invalid", "type": "https://developer.bigcommerce.com/api-docs/getting-started/api-status-codes", "errors": {} }

Seems like it occurred with '{' enter image description here

Any method that I can POST this script to head?


Solution

  • I believe src should be a URL to a script file.

    If you want to embed JavaScript then place it in the HTML field and wrap a tag around it.