How to send graphql query by postman? - graphql

I use
POST type
URL http://######/graphql
Body:
query: "query: "{'noteTypes': {'name', 'label', 'labelColor', 'groupName', 'groupLabel', 'imageUrl'}}"
But it return
"message": "Must provide query string."

There's a better way to do it using the REST client Insomnia
Docs are here, how to send graphql queries: https://support.insomnia.rest/article/61-graphql
Below are the steps for postman
Step 1.
Run the GraphiQL in Chrome, open the Chrome Dev Console, click the Network tab, and make the query from graphiql, when you make the query, network tab will show the graphql request...
Step 2.
From the graphql request copy the request query, Select the Copy as cURL (cmd)
Step 3.
Open Postman, In the Top-Left click on the Import button, after you click Import you have to click the Paste Raw Text, and paste the copied cURL request as done in step2 after it's done click the Import
Step 4.
Postman is ready to send the Graphql request, Just Click on the Send Button, you will see the Response in the Response Box in body as below
Step 5.
To see how the query is being sent click on the Body tab next to Headers, you will get know how to provide the fields from postman in JSON format.
e.g: edges {\n node {\n id\n jobId\n }\n, If you want to view another field then you need to add it in with the suffix \n
like if need name then : edges {\n node {\n id\n jobId\n name\n }\n
\n here just means to represent a new line. Instead, you can make it simpler by providing a clear and illustrative JSON like below
===========================================================================
Note: The body type must be raw with application/json content-type. So, the query must be a valid JSON with quotes ".."
{
"query":"{viewer {user {edges {node {id jobId name }}}}}"
}
===========================================================================
you can directly start from step 5 if you know how to send the query in body and other things too that needs to be required while making a request from postman
With simplified JSON

You don't need INSOMNIA in case the GraphQL server responds to Content-type: application/graphql or postman.setEnvironmentVariable,
Just do it:
In Headers tab:
Content-Type: application/graphql
In Body tab, "raw" selected, put your query

Adding this for anyone searching on the topic ... you can utilize and test GraphQL calls far better and more easily with Insomnia:
https://insomnia.rest
It's been fantastic for GraphQL development.

There's a simple way to do it. Use a pre-request script to stringify the payload (source).
Step 1.
In the body of the request put a placeholder for the payload.
{
"query":{{query}}
}
Step 2.
Create the payload in the pre-request script and store it in an environment variable.
postman.setEnvironmentVariable("query", JSON.stringify(
`
{
search(query: "test", type: ISSUE, first: 10) {
issueCount
edges {
node {
... on Issue {
title
id
state
closed
repository {
name
}
}
}
}
}
}
`
));
That's it.

UPDATE 8-2019 - I know this is old, but regarding POSTMAN, if you haven't figured it out already, they do have a graphql (beta) option for posting body. There is no need to add any additional headers.

UPDATE 2:
It's not practical use POSTMAN, because the are working yet in a easy way to add headers, that take longtime, and i think POSTMAN is not made for work naturally with graphql,
you can follow the progress about that here:
https://github.com/postmanlabs/postman-app-support/issues/1669
I recommend to use another packages plugin like:
the best (like postman , but profile and sync price 5$ monthly):
https://insomnia.rest/
others:
https://github.com/andev-software/graphql-ide
https://github.com/imolorhe
for graphiql (no add headers possibility) you need to set three things (it's not easy to type):
Header:
Content-Type: application/json
Body:
Choose Ray < optiongroup
Choose JSON (application/json) < selectbox
Compose javascript object with "query" and the "value" of your graph query. Like all objects in js it'sneeded the propery and the value , in this case "quote" is the property, the value must be with double quotes. Inside the value (graphl string) you dont compose js objects, so you dont need use doble quotes, it's just a string.
{"query":"{ allQuotes { text } }" }
the problem is you need type all in a single line, no like grapIql... there is a post requirement in postman github so is easy work with graphql:

Postman just released inbuilt GraphQL support in version 7.2.
This version supports
Sending GraphQL queries in request body as POST requests
Support for GraphQL variables
Creating APIs in Postman with GraphQL schema type
Query autocompletion integrated with user defined GraphQL schemas
Please give it a try and give us your feedback on the tracking thread on our community forum

I faced the same problem when I try to used graphQl query using POSTMAN,
In POSTMAN send data from the raw tab with json type.
Query Command:
{"query":"{user(id:902){id,username,DOB}}"}
Mutations Command:
{ "query": "mutation {createMutations(reviewer:36, comments:\"hello\",data_id: 1659, approved: true ){id}}" }
#commnent: String Type
#data_id:Int Type
#approved:Boolean Type

If you're using Visual Studio, I have written a plugin to convert GraphQL to Restful body
https://marketplace.visualstudio.com/items?itemName=orasik.graphql-to-rest-queries

Postman has recently launched its out of box support for GraphQL: https://blog.getpostman.com/2019/06/18/postman-v7-2-supports-graphql/
Below is the screenshot of testing GraphQL locally:
Note: Running GraphQL locally using spring-boot https://www.baeldung.com/spring-graphql

Deriving from Estevão Lucas' answer.
You can also use header Content-type: application/json on postman
And define the body with:
{
"query": "{ your_query }"
}
This is easily constructed on the client side to form a request payload.
e.g.
Output:

Checkout https://github.com/hasura/graphqurl - curl for GraphQL:
CLI for making GraphQL queries with autocomplete
Run GraphiQL locally against any endpoint (with custom headers)
Use as a library with nodejs or from the browser
Supports subscriptions
I am one of the authors.
gq https://gentle-anchorage-72051.herokuapp.com/v1alpha1/graphql -i

IF we can pass header type, Then add the header Content-type: application/graphql
Below link can be used as reference:
link description here

By adding header we can run graphql query in the postman
Content-type: application/graphql

Related

How to run a query with Apollo GraphQL?

I am trying to figure out how to write a query in Apollo GraphQL.
I have a schema and have run the application in development mode. I have authenticated through the front end.
I expect that I should be able to follow this documentation and query the user.
I can see from the studio, that the Me query should be capable of checking for my first name (which I can see is recorded in the database), but when I press run in Apollo Studio, I get a null response to the query.
Is there an assumed step to get this working that needs to be taken before queries can be run? It gets worse when I try to do a query on the users table generally. That returns a not authenticated error (I have authenticated in the local environment in the dev app).
I'm struggling to connect the dots between the documentation that shows how this is expected to run queries and the starting point. I suspect that these documents have been prepared with the expectation that users know something fundamental about how to engage with them. I'm looking for disclosure as to what those assumptions might be. I can see from this question that there is a need for an authorisation header, (although my error is to do with authentication rather than authorisation). However, in my studio, the headers tab is empty. How do I populate it and what do I use to populate it?
I can see from the Apollo dev tool that it is trying to use a logged in query. I don't understand what drives this query in the Apollo Studio. Inside the localhost web app (which is running), I am logged in. When I try and run that query in the dev tools, the isLoggedIn (name of the query) is underlined, with an error explanation appearing that says:
Cannot query field "isLoggedIn" on type "Query".
The response shows:
{
"data": {}
}
I am lost for a starting point to find something to try and solve.
I think, based on a comment in this Odyssey tutorial, that the sandbox does not know how to connect to my psql data (not sure about this, but how could it know what queries I have, and not know which data has been stored in the attributes on the schema?). My env variables include my psql attributes and my prisma migrate is up to date. How can I let the sandbox know where the data is stored?
I am trying to learn using this boilerplate repo.
For my next attempt, I tried using the login mutation to generate a token, that I could try adding to the header. I don't know if it needs to be added under the name 'authorization' or 'token', so I made headers with both attribute names and added the same token to each of them.
I tried running the me and user query again, and get a mouthful of gibberish in the response.
The link in the response text goes to a page that has the following error message:
> <Error> <Code>NoSuchKey</Code> <Message>The specified key does not
> exist.</Message> </Error>
When I try going through the process of adding an APOLLO_KEY to my env variables and starting the server, I get an error that says "Unable to reach server". When I run the diagnose script on that error, I get:
Could not find any problems with the endpoint. Would you please to let
us know about this at explorer-feedback#apollographql.com 🙏
I created a new api key and tried again and am able to connect. I am able to run a login mutation and can return my first name inside that mutation, but I cannot do it from the me or user query - those queries still return the unauthenticated error response.
I have tried adding the authorization token to the header field both with and without "", and I have tried labelling that attribute as each of authorization, Authorization, token and then each of those inside "". None of them seems to make any difference to whether I can run a query. How can I find the name of the header token that Apollo Studio Explorer will accept?
I also tried the syntax suggested in this post, which is key Authorization and value "Bearer token" (there are double quotation marks around that string and a space between the word Bearer (capitalised) and the token string). There are no curly braces. That doesn't work either.
I have also tried expressing it as shown in this page of the Apollo documentation, which I think means that the key of the header value should be Authorization and the value should be the word Bearer, immediately followed by the token string generated in the output of the Login migration, inside {{ }}. When I try this, I get the same response as each of the other attempts described above.
There is a difference in the responses though, I get an unauthenticated response on the user query, and a null response on the me query.
One final strange observation: the studio returns the above error and null responses, but if I use the apollo client dev tools in the browser console, I can run the same Me query and get the result.
The user query still returns an unauthenticated error when I run it in the dev tools.
I'd also note that I can ask for the firstName attribute, inside the Login mutation, and receive them back in that response. However, I can't access them inside a Me query itself.
The next thing I investigated was how the resolver was managing the data. The boilerplate includes a resolver with:
import { AuthenticationError } from "apollo-server-express"
import { createMethodDecorator } from "type-graphql"
import { ResolverContext } from "../resolverContext"
export function UseAuth(roles?: string[]): any {
return createMethodDecorator<ResolverContext>(async ({ context: { req } }, next) => {
const argRoles = roles || []
if (req?.currentUser) {
if (argRoles.length === 0) return next()
if (argRoles.includes(req.currentUser.role)) return next()
throw new AuthenticationError("Not authorized")
} else {
throw new AuthenticationError("Not authenticated")
}
})
}
I wondered if maybe the role wasn't being considered. But I can see that it is inside the login mutation, but is not in a query.
Is there a 'for dummies' guide to getting started with apollo graphql?
I hope this spares someone some angst.
The format that works in Apollo Studio Explorer is
Key: Authorization
Value: Bearer[space][token]
There are no curly braces and no quotation marks in any of this. See this post for more discussion about this.

The request body must contain the following parameter: 'client_id'

i have a simple spring boot app and i am using these dependencies in my build.gradle.kts for my oauth2 with azure ad:
implementation("org.springframework.boot:spring-boot-starter-oauth2-client:2.4.2")
implementation("com.azure.spring:azure-spring-boot-starter-active-directory:3.9.0")
I have a RestController that literally does not much. What it should do is, when i call localhost:8080/ i want azure ad be called and it should return my access token (not in the controller but at least i don't want to get any errors mentioned in the following sentences.).
#GetMapping("/")
fun helloWorld(): String? {
return "Hello Users!"
}
However, in the network tab of chrome, i see that there are several calls happening against login.microsoftonline.com. I even recieve the code in one of those requests. So looking pretty good so far.
The last call however fails and returns the following error:
[invalid_request] AADSTS900144: The request body must contain the following parameter: 'client_id'. Trace ID: XXXXXX Correlation ID: XXXXXX Timestamp: 2021-09-30 13:15:30Z
I don't get it, because in one of the requests mentioned above, the client_id is included. So it gets correctly loaded out of my application.properties. I ofc also set the tenant_id and the secret in the app.props.
On google i could not find anything useful about that error, so i hope you can help me :)
Thanks in advance!
There are usually two causes for this error.
The parameter: ‘client_id’ is missing from the request, therefore ensure the authentication request includes the required parameter.
If you are hitting the token endpoint (i.e. https://login.microsoftonline.com/common/oauth2/token ), the Content Type is not set correctly. Ensure the content type is 'application/x-www-form-urlencoded' as a header in the request body.
Also check this so reference .
Ok, so here are my two cents.
I am using the VsCode RestClient Extension and I am trying the POST Request as follows.
# This does NOT work
POST https://login.microsoftonline.com/35b02984-c026-40c5-8cb3-2267c184d48a/oauth2/v2.0/token HTTP/1.1
content-type: application/json
{
"grant_type": "client_credentials"
}
I tried tweaking this in every which way, but always got this error message.
The request body must contain the following parameter: 'grant_type'
{
"error": "invalid_request",
"error_description": "AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: 71b6d6f5-4d0d-408b-b702-a935ec73f601\r\nCorrelation ID: 4684f398-ef8b-42f3-9016-fdc8458b1730\r\nTimestamp: 2022-09-30 06:36:12Z",
"error_codes": [
900144
],
"timestamp": "2022-09-30 06:36:12Z",
"trace_id": "71b6d6f5-4d0d-408b-b702-a935ec73f601",
"correlation_id": "4684f398-ef8b-42f3-9016-fdc8458b1730",
"error_uri": "https://login.microsoftonline.com/error?code=900144"
}
Finally this SO Question came to the rescue.
So now I modified the request to the following and this works.
POST https://login.microsoftonline.com/35b02984-c026-40c5-8cb3-2267c184d48a/oauth2/v2.0/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: Basic trusted:secret
grant_type=client_credentials
&scope=https://graph.microsoft.com/.default
&client_id=e7f0a65e-d4b8-499f-96c9-d92e3df41e14
&client_secret=JUx8Q~xiMv2hb9OVKz8xtc.cCHvqBvcqpH4sKb4K

How can I use the bot composer to dynamically configure the body part of a HTTP REQUEST

I am using Bot Composer to publish my first chatbot. I need to construct the chatbot to send out an HTTP POST request to fetch external resources from a remote website. As specified by the composer interface, I can embed JSON, form data, or string in the body of the HTTP POST request. Instead of hard-coding the body part of the POST request, I need to pass in one or multiple properties (chatbot's variable) to generate the body of the HTTP POST dynamically. Here are my questions:
(1) can I pass a variable to the body part of the HTTP REQUEST (such as POST)? can I embed a property such as $(user. name) in the HTTP POST body?
For example, can I embed a property such as $(user.name) in a string or form data (such as fname=$(user. name) to construct the body part of the HTTP POST REQUEST?
(2) The document specifies that there is a pre-build function JSON to serialize data. If I understand correctly, I can't pass a variable (such as $(user. name) to the JSON pre-built function. Therefore, I will probably need to embed an expression in the body to pass the variable. Yet, I couldn't find any detailed information. Is there anywhere I can find a good example showing how to write an expression inside the body part of the HTTP REQUEST
Thanks for any information/assistance.
Yes, you can do this. The simplest way is to set the body to Object and then put in your structured json, something similar to:
{
"userinfo": {
"username": "${user.username}",
"name": "${user.personalname}",
"favoritecolor": "${user.favcolor}",
"profileupdated":"${dialog.userprofileuptodate}"
}
}
I am trying to figure out how to set it up in an adaptive expression in LG, and then be able to refrence it with something like:
# APIBodyTemplate()
-```
{
"userinfo": {
"username": "${user.username}",
"name": "${user.personalname}",
"favoritecolor": "${user.favcolor}",
"profileupdated":"${dialog.userprofileuptodate}"
}
}
```
And then using something like the following in an expression in the body field:
=json(APIBodyTemplate()), but that is not quite working yet. Might be a bug. I will update when I have more info.

The method Files.get does not return the full file response

I use google-drive-api from this link.
But I find my response is different from the api website.
My response:
{
"kind": "drive#file",
"id": "1hs6V6eDa6CYd3gtkAeRKlrOezLYpDWTfWh5VFtchFYA",
"name": "Test001",
"mimeType": "application/vnd.google-apps.spreadsheet"
}
You can see it:
But the documented file response object is very detailed.
Why are these two response results different?
Normally by default, the server sends back the full representation of a resource after processing requests. For better performance, you can ask the server to send only the fields you really need and get a partial response instead.
Google Drive api v3 has partial response enabled for most of the methods by default. To request a partial response, use the fields request parameter to specify the fields you want returned. You can use this parameter with any request that returns response data.
Example:
returns only Kind, items.title,
&fields=kind,items(title)
or
Returns everything
&fields=*
Tip: In the try me click Show standard parameters you will be able to add fields

Passing parameters to JMeter

I can successfully pass parameters through Jmeter as long as I embed them in the path like so:
But when I try to add them using the GUI, it doesn't work:
I have tried combinations of encode/unecode, as well as adding "?" to the path, but the result is the same - the server replies that the required parameter is missing. Any ideas?
This is a post request so pass this name value into Body data (click on body data tab) in json format
{
"Taskid": "9000"
}
or
{
"Taskid": 9000
}
if the type of 9000 is string then choose 1st option other wise 2nd, better to try with both options to check which one is working
Other approach:
try to change the method to get with same parameters as passed in snapshot2 (attached by you) but it might be possible this request does not supports get method then in that situation you have to post it only by passing in the Path field (as shown by you in snapshot 1) or in body data tab

Resources