Please be aware there is a known issue with images on the Community. We are working to resolve this issue as quickly as possible. We apologize for the inconvenience. If you need urgent help in the meantime, please reach out to technical support or your Threekit representative.

Getting Cors Error

Comments

7 comments

  • Ian  Drews
    Ian Drews

    Hi Vikram,
    Are you passing in your bearer token as a query parameter or as a header? if you're calling the orders API through the browser it needs to be passed through a query parameter, if that isn't the issue could you post your full API call here and I can take a look. 
    Ian

    0
  • vikram_s
    vikram_s

    Hi Lan Drews,

    I have tried with query parameter then I am getting (method not allowed). So I am sharing a snippet with you please check and let us know.

    var myHeaders = new Headers();
    myHeaders.append("Authorization", "Bearer bear_token_value");
    myHeaders.append("Content-Type", "application/json");
    myHeaders.append("Access-Control-Allow-Origin", "*");


    var raw = JSON.stringify({
      "name": "Sofa",
      "customerId": "organization_token_value",
      "originOrgId": "organization_token_value",
      "platform": {
        "id": "1900",
        "platform": "Testing",
        "storeName": "Testing"
      },
      "metadata": {
        "name": "Vikram",
        "email": "vikram@example.com"
      },
      "cart": [
        {
          "configurationId": "121212",
          "count": 1
        }
      ],
      "status": "List",
      "orgId": "organization_token_value"
    });

    var requestOptions = {
      method: 'POST',
      headers: myHeaders,
      body: raw,
      redirect: 'follow'
    };

    fetch("https://preview.threekit.com/api/orders", requestOptions)
      .then(response => response.text())
      .then(result => console.log(result))
      .catch(error => console.log('error', error));


    Thanks

    0
  • Ian  Drews
    Ian Drews

    Hi Vikram, I was able to get it working formatted like this. I'll contact our documentation team about unclearness in that article as well.

    varmyHeaders=newHeaders();

    myHeaders.append("Content-Type", "application/json");

    varraw=JSON.stringify({

    name:"Sofa",

    customerId:"organization_token_value",

    originOrgId:"organization_token_value",

    platform: {

    id:"1900",

    platform:"Testing",

    storeName:"Testing",

    },

    metadata: {

    name:"Vikram",

    email:"vikram@example.com",

    },

    cart: [

    {

    configurationId:"121212",

    count:1,

    },

    ],

    status:"List",

    orgId:"{ORGIDVALUE}",

    });

    varrequestOptions= {

    method:"POST",

    headers:myHeaders,

    body:raw,

    redirect:"follow",

    };

    fetch(

    "https://preview.threekit.com/api/orders?bearer_token={BEARERTOKENVALUE}",

    requestOptions

    )

    .then((response) => response.text())

    .then((result) => console.log(result))

    .catch((error) => console.log("error", error));

    Ian

    0
  • vikram_s
    vikram_s

    Hello Lan,

    I hope you understand. We need the resolution on it ASAP.

    Have you tried this implementation at your end?

    0
  • Ian  Drews
    Ian Drews

    I have tried this implementation in a browser and it was working yes.

    0
  • vikram_s
    vikram_s

    How we can create orders on the Threekit server with GET method. I have checked Threekit order API docs, We can create orders only with the POST method.
    Just please let me know, Can we call this API from the ReactJS front-end application or not.

    0
  • Ian  Drews
    Ian Drews

    I'm a little confused Vikram, yes you can call this method from the frontend the issue was with the way that the token was being passed in. You are correct that you call orders with the POST not GET. The implementation I posted above is using the POST method and I have gotten it working in the browser. Is it failing with the same error for you?

    0

Please sign in to leave a comment.

Powered by Zendesk