Cypress - GraphQL response = operation not found - graphql

I consistently receive the response of 'operation not found' when I send a GraphQL query or mutation in Cypress. Taking tips from this post https://stackoverflow.com/a/68750026/16958500 I have the following in my it block (its working in Postman)
it('Retrieve and Store Session Token', () => {
const query = `mutation {
requestSMSSessionToken(phoneNumber: "1666555021"){
cookieKey
tokenValue
expires
}
}`;
cy.request({
method: 'POST',
url: '/',
headers: {
'Content-Type': 'application/json',
},
body: { query },
}).then((res)=>{
cy.log(JSON.stringify(res))
expect(res.status).to.eq(200)
});
})
Here is my Postman Curl Code Snippet (that's working)
curl --location --request POST '/' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"mutation {\r\n requestSMSSessionToken(phoneNumber: \"1666555021\"){\r\n \r\n cookieKey\r\n tokenValue\r\n expires\r\n \r\n }\r\n }","variables":{}}'
any tips to share to get this working?

Related

conver to ajax to curl -> curl localhost:8080/oauth/token -h foo:bar -d grant_type=password -d username=test#gmail.com -d password=1

I want conver to ajax to curl.
curl localhost:8080/oauth/token -h foo:bar -d grant_type=password -d username=test#gmail.com -d password=1
The above command succeeds.
but ajax fail...
$.ajax({
url: 'http://localhost:8080/oauth/token',
type: 'POST',
dataType: 'json',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Basic' + btoa('foo:bar'));
},
data: {
grant_type: 'password',
username: 'test#gmail.com',
password: '1'
},
complete: function(result) {
console.log('complete', result);
},
success: function(result) {
console.log('success', result);
},
error: function(result) {
console.log('error', result);
}
});
I converted to ajax and the following error appears.
Response for preflight has invalid HTTP status code 401
responseJSON : undefined
What is the problem?
I found solution.
Modify OauthServer
Change "source.registerCorsConfiguration("/**", configAutenticacao);" to "source.registerCorsConfiguration("/oauth/token", configAutenticacao);" in corsFilterRegistrationBean

PUT on ajax instead of curl

I have this curl URL to connect to couchDB.
curl -X PUT http://admin:ulacit#13.90.93.32:5984/test/"001" -d '{"name":"moises"}'
I saw a lot of questions with GET and POST but I didn't find an example with PUT.
Am I doing this the right way?
$.ajax({
crossOrigin: true,
url : 'http://admin:ulacit#13.90.93.32:5984/test/'+user,
type : 'POST',
processData: false,
dataType: 'json',
contentType: 'application/json',
data: {pass:pass,email:email},
success:function(result){
if(result!="error"){
alert("Registro Correcto, Proceda a entrar");
open("login.html","_parent" );
}else{
alert("Usuario Ya Utilizado");
}
},
The PUT HTTP verb is used to either:
create a database e.g. curl -X PUT http://localhost:5984/mydb
create a document in a database when you know the id of the document you wish to create e.g.
# create a document with PUT with document id in the URL
curl -X PUT -d '{"a":1,"b":2}' -H 'Content-type: application/json' http://localhost:5984/mydb/mydocid
{"ok":true,"id":"mydocid","rev":"1-25f9b97d75a648d1fcd23f0a73d2776e"}
which is the equivalent of:
# create a document with POST with the document id in the body
curl -X POST -d '{"_id":"mydocid","a":1,"b":2}' -H 'Content-type: application/json' http://localhost:5984/mydb/mydocid

AJAX vs. curl request header formatting -- header as object or string in JQuery?

My API responds to the following curl request:
curl --data "session[email]=email#gmail.com&session[password]=password" -H 'Accept: application/vnd.my-app.v1' \http://my-app.dev/sessions
But not to this Ajax:
$.ajax({
url: '/sessions',
method: 'POST',
headers: 'Accept: application/vnd.superstar-is-back.v1',
data: {
session: {
email: this.email,
password: this.password,
},
}
})
Am I getting something wrong with this syntax?
I'm not sure how this impacts Rails Routing, but based on the jQuery docs, I think the headers property needs to be an object: headers: { Accept: 'application/vnd.superstar-is-back.v1' }

Parse cloud code: We are trying to call Spreedly API which in xml in cloud code

I am struggling to call an external API which is supported only for XML using HTTP Request (parse.cloud.httprequest). The cURL request format is :
curl https://core.spreedly.com/v1/gateways/UD0s1PcwgI55XJefzrlBBQMwaUj/purchase.xml -u '60lRz6BfKxHESwJaVSf4kiZpu5O:xVqRwqem0KEuthvE9n8aIE1Al8FVL2QwdC2z8cS8jQYXAQER18wMW8SD6BhOF4fX' -H 'Content-Type: application/xml' -d 'YsTXXDhYwePyMW8KlgeOmkZ1qlR100USD'
This (above) works fine. Now I need to call this XML API from Parse cloud function. The parse documentation on HTTP Request shows only examples of JSON not XML. Here is what I am using in HTTP Request cloud method but it is failing with 401 error.. Please help.
Parse.Cloud.httpRequest({
method:'POST',
url: url1,
headers: {
'Content-Type': 'application/xml',
'Authorization' : "'"+environment_key+":"+access_secret_key+"'"
},
data: "<transaction><payment_method_token>cust_token</payment_method_token><amount>amount</amount><currency_code>currency_code</currency_code></transaction>"
}).then(function(httpResponse) {
var response1=httpResponse.data;
console.log("res :"+response1);
response.success(response1);
}, function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
response.error('Request failed with response code ' + httpResponse.status);
});

Convert Parse Token Curl to Ajax

I need to convert this to ajax.
curl -X POST \
-H "X-Parse-Application-Id: ****************" \
-H "X-Parse-REST-API-Key: ******************" \
-H "Content-Type: application/json" \
-d '{
"deviceType": "ios",
"deviceToken": "result" ,
"channels": [
""
]
}' \
https://api.parse.com/1/installations
I found the solution is to create an ajax post method. So in this example, you would do the following ajax method.
var headers = {
"X-Parse-Application-Id":"Your ID",
"X-Parse-REST-API-Key":"Your Rest API Key"
};
// Convert data object to JSON string:
var userData = { "deviceType": "the device or the variable that says the device",
"deviceToken": "The Token itself or the variable with the token",
"channels": [""]
};
var data = JSON.stringify(userData);
$.ajax({
headers: headers,
type: 'POST',
url: "https://api.parse.com/1/installations",
contentType: "application/json",
data: data,
dataType:"json",
success:function(data) {
// We log the responce from the server just to check.
alert("data:" + JSON.stringify(data) + " status: " + status);
},
error:function(data) {
// Show error message:
alert("Your data didn't save!" + JSON.stringify(data));
}
});

Resources