Team,
We are facing the odd issue in graphQL which used in NexarAPI. For me, it is working fine while sending setting basic query – { “query”: “query Categories { supCategories { id name path }}”} and content type set as application/json. We are able to retrieve the data from Altium with this query
But if we specify workspace and other stuff in the query – “{ “query”: “query design2_Library { desLibrary (workspaceUrl: “test”) { components { nodes { id name manufacturerParts { partNumber companyName } details { parameters { name value } } } } } }” }”
It throws the error as,
<200,{“errors”:[{“message”:”Expected a String
-token, but found a Name
-token.”,”locations”:[{“line”:1,”column”:64}],”extensions”:{“code”:”HC0011″}}]},[Date:”Fri, 21 Jun 2024 11:16:40 GMT”, Content-Type:”application/json; charset=utf-8″, Transfer-Encoding:”chunked”, Server:”Kestrel”, Cache-Control:”proxy-revalidate”, X-SYMC-Transaction-UUID:”8b74d844d6cf25c1-000000000b3ff64b-0000000066756118″, Connection:”keep-alive”]>
Even i tried with changing content type as graphql, but it throws 404 error during that. Please share your suggestion on this case and find below source code
public String getComponent(String query) { logger.info("getComponent {Query:" + query + "}"); try { Context initContext = new InitialContext(); Map token = generateOAuthAcessToken(initContext, "QA"); String url = nexarEndPoint; UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url).queryParam("partNo", query); HttpHeaders headers = new HttpHeaders(); headers.setAccept( Arrays.asList(new MediaType[] { MediaType.valueOf("application/graphql-response+json") })); headers.setContentType(MediaType.valueOf("application/graphql-response+json")); // headers.setContentType(customMediaType); headers.add("Authorization", "Bearer " + token.get("access_token")); String alternateQuery = "{"query":"query design2_Library { desLibrary (workspaceUrl: \"<altium workspace url>\") { components { nodes { id name manufacturerParts { partNumber companyName } details { parameters { name value } } } } } }","variables":{}}"; query = "{ "query": "query Categories { supCategories { id name path }}"}"; String graphqlQuery = "{ "query": "query design2_Library { desLibrary (workspaceUrl: "test") { components { nodes { id name manufacturerParts { partNumber companyName } details { parameters { name value } } } } } }" }"; // String graphqlQuery1 = "{ "query": "query design2_Library { desLibrary System.setProperty("https.protocols", "TLSv1.2"); HttpEntity<String> entity = new HttpEntity<String>(query.toString(), headers); RestTemplate template = new RestTemplate(); ResponseEntity<String> response = template.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class); String result = response.getBody(); JSONArray resultArr = new JSONObject(result).getJSONObject("data").getJSONObject("desLibrary") .getJSONObject("components").getJSONArray("nodes"); return resultArr.toString(); } catch (Exception ex) { logger.error("Search value " + query + "n" + ex.getMessage()); return "Error : " + ex.getMessage(); } }
Solaiappan Elangovan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.