0

this is my first question to this great community, so please have mercy.

I currently have following problem:

I want to recieve data from Bosch IoT API, but even following their documentation (https://bosch-iot-insights.com/static-contents/docu/html/Java.html >> Synchronous query execution - Example) didnt help me.

My code looks exactly the same as theirs:

        String resourceUrl = "https://bosch-iot-insights.com/mongodb-query-service/v2/my-project";

        String username = "my-user";
        String password = "my-pw";
        String authorizationCredentials = generateAuthorizationToken( username, password );

        String payload = new String(Files.readAllBytes(Paths.get("C:/Users/my-name/Desktop/payload.json")));
        String contentType = "application/json";


        WebResource service = Client.create().resource( resourceUrl );
        ClientResponse response = service.header( "Authorization", authorizationCredentials )
                .header( "Content-Type", contentType )
                .post( ClientResponse.class, payload );

        System.out.println( response );

        if ( response.getStatus() == 200 ) {
            System.out.println( parseJson( response.getEntity( String.class ) ) );
        } 

I've also tried some solutions with C# and PHP, but they all had the same output: 403 Forbidden When I am opening the project URL I can normally log in, but then I get obviously a 405 Method not allowed - Error, because there is no GET-Method.

I even contacted them and asked for help, but with my credentials they were getting following result:

POST https://bosch-iot-insights.com/mongodb-query-service/v2/my-project/execute-aggregation-query returned a response status of 200 OK
[
  {
    "key": value
  }
]

I know what the Status Code 403 means, but even Bosch can't help me in this problem, because for them everything looked fine..

I'd appreciate and be very grateful if someone could help me or give me some ideas why this error is being produced.
(For more information feel free to ask!)

  • Just one thing I noticed : In the documentation `contentType` is `text/plain` and you are using `json`. – dariosicily Mar 24 '20 at 14:26
  • Your "question" is not clear. `response.getStatus()` is not returning 200? What is it returning? 403? 405? Something else? Is there a "response" message? Can you post the `authorizationCredentials` and the `payload`? Perhaps you have an error in one of them? – Abra Mar 24 '20 at 14:28
  • @dariosicily I have to send data to a MongoDB, so I use application/json (btw, you were looking at the wrong code, you have to look at the block after the first code with the headline "Synchronous query execution") – Patrick Schulz Mar 24 '20 at 14:47
  • @Abra I unfortunately can't send you the credentials, because they're from another company. But I can safely say, that the credentials and the payload are correct, because Bosch already tested them The response message: POST https://bosch-iot-insights.com/mongodb-query-service/v2/my-project/execute-aggregation-query returned a response status of 403 Forbidden – Patrick Schulz Mar 24 '20 at 14:49
  • @Abra The PHP output looks like this: HTTP/1.1 403 Forbidden ... "message":"Access is denied","path":"/mongodb-query-service/v2/my-project/execute-aggregation-query"} – Patrick Schulz Mar 24 '20 at 14:53

0 Answers0