Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

403 forbidden response

pprrdd
Kilo Explorer

Hi,

I am trying to create an incident using my instance.

HttpPost httpPost = new HttpPost("https://myinstance.service-now.com/api/now/table/incident");

httpPost.setHeader("Accept", "application/json");

httpPost.setHeader("Content-Type", "application/json");

HttpEntity entity = new ByteArrayEntity(postData.getBytes("utf-8"));

httpPost.setEntity(entity);

System.out.println("Executing request " + httpPost.getRequestLine());

CloseableHttpResponse response = httpclient.execute(httpPost);

try {

  System.out.println("----------------------------------------");

  System.out.println(response.getStatusLine());

  String responseBody = EntityUtils.toString(response.getEntity());

  System.out.println(responseBody);

} finally {

  response.close();

}

I get a 403 forbidden response back from the webservice.

HTTP/1.1 403 Forbidden

{"error":{"message":"Operation Failed","detail":"Error during insert of incident (INC0000001)"},"status":"failure"}

Not sure where is it going wrong. I am sending the json in the postData variable. Not sure if it is the input json data which is causing the issue.

4 REPLIES 4

Jace Benson
Giga Sage

403 is a forbideen error generally has to do with authentication.   You didn't say anything about authentication.   Are you able to query a table with a GET using the same headers?


Yes, It is definitely related to authentication, actually the ACL related authentication. I am able to do a GET request and successfully get a response. I have tried adding access specific roles to the USER and also matched the roles of user with table ACL list. I either get 403 forbidden or 401 user not authorized. This is on my second instance, the first instance works fine.


Thanks,


Priyank


I know I said it before.   Are you declaring the auth ahead of time or did you just exclude the header "Authentication: Basic _BASE64dusername:_password" against the problem instance?   Could it also be that you tested the first instance after you auth'd in a different script?


Right now I dont have the auth header, it used to work before without adding the entry to the header. what exactly do I need to do to add it to the header.


Thanks,


Priyank