How to add HTTP headers to call external API ?

abhi34
Kilo Contributor

I have been trying to call an external API(Zendesk API) from the SN personal instance Previously , i would use the following code in my server side script(on NodeJS) and it would work perfectly fine . 

app.get("/api/v2/tickets/:TICKET_ID/comments.json", function(req, res) {
    debugger;
    var options = {
      method: "GET",

      url:
        process.env.ZENDESK_HOST +
        "/api/v2/tickets/" +
        req.params.TICKET_ID +
        "/comments.json",
      headers: {
        authorization: process.env.ZENDESK_TOKEN
      }
    };

    request(options, function(error, response, body) {
    //Somecode
  });

Now i am trying to do the same in ServiceNow.  The problem i am facing is how do i  add the headers(which can be seen above ) in ServiceNow HTTP request . 
My approach in (ServiceNow) has been to create a new REST Message(call it test2 )  : 

1.)Fill in the endpoint 

2.) Selected ->AUTHENTICATION TAB ->Add authorisation(tried both basic and NO authorization ) . While trying basic  created a new "Basic Auth Configurations" and added some random username and password. 

3)Selected ->HTTP REQUEST -> Tried adding Headers , but the add(+) button wont work . 

See below : 

find_real_file.png

 

4.)Anyhow submitted the REST Message and Selected "Test" ,and then  i see this  : 
4a.)HTTP Status : 401 

4b.) Error Message :  Invalid username/password combo

4c.)Response : {"error":"Couldn't authenticate you"}

 

After this i returned to STEP 3 to add headers , just in case . But it is still unclickable . 
I tried reading through the documents to call API in SN , and tried many approaches but none seem to work for me . 

 

Any help will be greatly appreciated . 

 

 

1 ACCEPTED SOLUTION

DScroggins
Kilo Sage
Hello. You can double click on the message 'Insert a new row...' under the name column to add the header. Then double click on the white space under the value column to add the header value. Hope this helps.

View solution in original post

2 REPLIES 2

DScroggins
Kilo Sage
Hello. You can double click on the message 'Insert a new row...' under the name column to add the header. Then double click on the white space under the value column to add the header value. Hope this helps.

abhi34
Kilo Contributor

Thanks a lot !!! 
I tried doing something similar to what you just said . What i tried was double click on 
Insert a new row" but this does not work . First the value has to be added . 

You saved a lot of time of mine. 🙂