Getting Cors Error

vikram_s

Hello William Thompson,
I am getting CORS error, when I am calling orders API and I have already whitelist my token on Threekit under token.



We are calling this API using ReactJS. Please suggest what we need to do?

Comments

7 comments

  • Comment author
    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
  • Comment author
    vikram_s
    • Edited

    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
  • Comment author
    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
  • Comment author
    vikram_s

    Hello Lan,

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

    Have you tried this implementation at your end?

    0
  • Comment author
    Ian Drews

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

    0
  • Comment author
    vikram_s
    • Edited

    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
  • Comment author
    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.