Request Headers

Hello! We're trying to make API calls to the website we're using (http://docs.semantics3.com/v1.0/docs/endpoints) and it requires a header for the api key. How would I do this in Kinoma? I've made API calls without using headers before, but not sure how to invoke the handler when it requires a header. For reference, this is what the call looks like in terminal: curl -G -H "api_key: YOUR_API_KEY" https://api.semantics3.com/test/v1/products --data-urlencode 'q={"search":"apple iphone"}'

Comments

  • Hello! You can add any custom header you need with the setRequestHeader(string, string) method of the Message object. It just takes simple key-value pairs. The code snippet below should get you on your way.

    var url = "https://api.semantics3.com/test/v1/products?";
    var msg = new Message(url + serializeQuery({search:"apple iphone"}));   
    msg.setRequestHeader("api_key", "YOUR_API_KEY");
    msg.method = "GET";
    

    Cheers,

    Will

  • Hi Will, Can you please tell me what will be the code for POST request. I want to send some JSON data in the request. For example: url : 127.0.01/abc data to be sent : {lmn: 'rock'} method: POST

    What will be the code for this example?

    Thank you

Sign In or Register to comment.