How can test api in postman

#1

hi
i want to test api using postman but i don’t know how add token in postman

#2

Token can be generated from your profile.
Please see how it looks in my system

use the generated token in Postman
Please see below

#3

thank you
now i can send request and get answer using post man and i test get api using spring boot in java successfully but i can’t do post in java spring boot.
can you help me to do that.

static final String URL_POST_CREATE_USER = "http://192.168.1.103:8118/api/v1/users/create";

HttpHeaders postHeaders = new HttpHeaders();
postHeaders.setContentType(MediaType.APPLICATION_JSON);
postHeaders.set(“accesstoken”,“3c24057810da196803bb979d0038b1963fe93f6a”);

MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
List aGrps = new ArrayList<>();
body.set(“aUsername”, “moosavi5”);
body.set(“aPass”, “12345678”);
body.set(“aPassConfirm”, “12345678”);
body.set(“aFullname”, “seyyed moosavi”);
body.set(“aEmail”, "email5@email.com");
body.set(“aRole”, “user”);
body.set(“aTitle”, “moosavi nazar”);
aGrps.add(“5c6b081e2a992c0bda91a28c”);
body.set(“aGrps”, aGrps);
HttpEntity<MultiValueMap<String, Object>> accountEntity = new HttpEntity<>(body, postHeaders);

RestTemplate restTemplate = new RestTemplate();

ResponseEntity postResponse = restTemplate.exchange(URL_POST_CREATE_USER, HttpMethod.POST,
accountEntity, String.class);

String postResult = postResponse.getBody();

System.out.println("postResult: " + postResult);

Error is:

org.springframework.web.client.HttpClientErrorException: 400 Bad Request
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:118)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:103)
at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:730)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:688)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:644)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:564)
at com.microservice.service.TestRestApi.test(TestRestApi.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
#4

I’m not familiar with spring boot. Its outside the scope of this project. As you’ve tested the API with postman you can see that my API is working correctly.

The best advice I can give is figure out what the post body actually looks like when coming from your java client. The 400 status is returned when trudesk is having trouble parsing the request body.