I'm using Parse.Cloud.httpRequest and I need to send basic authentication with only a username to balanced payments. Where does this go and what would that look like? I tried setting it in the Headers but that's not working.
Parse.Cloud.httpRequest({
method:'POST',
url: customerUrl,
headers:{
"Content-Type" : "application/x-www-form-urlencoded",
"Accept" : "application/vnd.api+json;revision=1.1",
"Authorization" : balancedSecret
},
body:bodyJsonString,
success: function(httpResponse) {
console.log(httpResponse.text);
response.success(httpResponse.text);
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
response.error(httpResponse.text);
}
});
When I call the function I get:
"errors": [
{
"status": "Unauthorized",
"category_code": "authentication-required",
"description": "Not permitted to perform create on customers. Your request id is OHMca9c440a0a7811e4ba9202a1fe52a36c.",
"status_code": 401,
"category_type": "permission",
"request_id": "OHMca9c440a0a7811e4ba9202a1fe52a36c"
}
]
"Authorization" : balancedSecret
This is going to be wrong. You use the secret as the username, and nothing as the password. You then concatenate them together, base64 encode them, and pass that as the value of the auth header.
I don't have the setup to double check this, but this should work as the value:
"Basic " + encodeBase64(balancedSecret + ":")
Giving this code:
authHeader = "Basic " + btoa(balancedSecret + ":")
Parse.Cloud.httpRequest({
method:'POST',
url: customerUrl,
headers:{
"Content-Type" : "application/x-www-form-urlencoded",
"Accept" : "application/vnd.api+json;revision=1.1",
"Authorization" : authHeader
},
body:bodyJsonString,
success: function(httpResponse) {
console.log(httpResponse.text);
response.success(httpResponse.text);
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
response.error(httpResponse.text);
}
});
Related
I'm trying to used the rest API of firebase with react native. I'm trying to used the notification request but my fetch doesn't work .
I have an error like that :
Possible Unhandled Promise Rejection (id: 10):
SyntaxError: JSON Parse error: Unexpected EOF
i also console.log the response i get this :
{"_bodyBlob": {"_data": {"__collector": [Object], "blobId": "1223679F-6B8F-4104-9085-060585EDF71E", "name": "1.1", "offset": 0, "size": 0, "type": "text/html"}}, "_bodyInit": {"_data": {"__collector": [Object], "blobId": "1223679F-6B8F-4104-9085-060585EDF71E", "name": "1.1", "offset": 0, "size": 0, "type": "text/html"}}, "bodyUsed": false, "headers": {"map": {"alt-svc": "h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"", "content-length": "0", "content-type": "text/html", "date": "Tue, 06 Apr 2021 14:20:39 GMT", "server": "scaffolding on HTTPServer2", "x-content-type-options": "nosniff", "x-frame-options": "SAMEORIGIN", "x-xss-protection": "0"}}, "ok": false, "status": 404, "statusText": undefined, "type": "default", "url": "https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send%20HTTP/1.1"}
this is my fetch and i call him on the componentdidmount of my app.js
Notif = async () => {
const headers = new Headers({
'Content-type': 'application/json',
Authorization: 'Bearer ' + (await AsyncStorage.getItem('token')),
message:{
token:"ff_Zolz1s0mmgrovad27JG:APA91bHlV5bAXyNHI3aWGyjltdgmJP8mmGBlEC0mPBA72IIJGqoliH4gm1rCQp0szQ5JypKxNhcWcKb7JrOwUTZDmaCB02y4dS553WVDdsxbWuLeK7cqoMjTRjFtFfdMb8bVGxO65BTq",
notification:{
body:"This is an FCM notification message!",
title:"FCM Message"
}
}
});
const options = {
method: 'POST',
headers: headers,
};
fetch('https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1', options)
.then((response) => {
console.log(response);
return response.json();
})
.then(
(err) => {
console.log(err);
},
);
};
Firstly you are handling the fetch request incorrectly as it is missing a catch clause. Secondly, check the url you are sending in the request as it seems to not be properly formatted as a string.
Side note you could await the fetch function since you already made the Notfi function asynchronous and surround this with a try/catch block.
Getting the user just passing the user id works fine:
const { data: response } = await axios.get(`${ MS_GRAPH_USER_API }/${ id }`, {
headers: {
Authorization: `Bearer ${ TOKEN }`,
"Content-Type": "application/json"
}
})
However, this:
const { data: response } = await axios.get(`${ MS_GRAPH_USER_API }/${ id }?$expand=extensions`, {
headers: {
Authorization: `Bearer ${ TOKEN }`,
"Content-Type": "application/json"
}
})
returns the following error:
data: '{"#odata.context":"https://graph.microsoft.com/v1.0/$metadata#users(extensions())/$entity"{\r\n' +
' "error": {\r\n' +
' "code": "InternalServerError",\r\n' +
"message": "The entity instance value of type 'microsoft.graph.user' doesn't have a value for property 'id'. To compute an entity's metadata, its key and concurrency-token property values must be provided.",\r\n +
' "innerError": {\r\n' +
' "date": "2020-12-19T09:51:26",\r\n' +
' "request-id": "93cf5d97-0096-4769-871e-f8fcf7cd17c3",\r\n' +
' "client-request-id": "93cf5d97-0096-4769-871e-f8fcf7cd17c3"\r\n' +
' }\r\n' +
' }\r\n' +
'}'
Why is that? The user has an extension added to his/her profile.
Seems like you need to include a select clause in the URL before the expand clause, i.e.:
$select=businessPhones,displayName,givenName,jobTitle,mail,mobilePhone,officeLocation,preferredLanguage,surname,userPrincipalName,id&$expand=extensions
just had to try a few different google searches before finding this:
why does Microsoft Graph require $select with $expand=extensions?
Using pact to verify if the response header matches for the consumer and provider.
Running the pact verification on the provider side gives me the following error:
Failure/Error: expect(header_value).to match_header(name, expected_header_value)
Expected header "abc" to equal "xyz", but was nil
However, when I inspect if my response header, it gives me the expected value ("xyz").
Here is the sample pact file I'm trying to verify:
"interactions": [
{
"description": "a request to do something",
"request": {
"method": "get",
"path": "/example"
},
"response": {
"status": 200,
"headers": {
"abc": "xyz"
}
}
}]
I’m new to pact. Any help would be appreciated.
While this is an old post, I hope this will help anyone who views this.
I'm not familiar with ruby, however if your using a basic HTTP Rest request you need to add the accept headers on the 'withRequest' as well as the expected headers on the 'withRespondWith'. You can use Postman to view both request and response headers; JavaScript Example:
describe('When a request is made to get all <resources>', () => {
beforeAll(() =>
provider.setup().then(() => {
provider.addInteraction({
uponReceiving: 'a request to receive to receive all...',
withRequest: {
method: 'GET',
path: '/<resource>',
// Default headers from Axios documentation
headers: { Accept: "application/json, text/plain, */*" }
},
...
willRespondWith: {
// expected headers
headers: { "Content-Type": "application/json; charset=utf-8" },
...
I am trying to get the data from neo4j database which is at a remote location for which I make a ajax request which is as follows:
$.ajax({
type: "POST",
// headers: {"Access-Control-Allow-Origin": "*"},
url: "http://<mysite>.sb04.stations.graphenedb.com:24789/browser/",
headers: {
"Authorization": "Basic " + btoa('email' + ":" + 'mypw')
},
crossDomain: true,
accepts: { json: "application/json" },
dataType: "json",
data: {
"query": "start n = node(*) return n",
"params": {}
},
success: function (data, textStatus, jqXHR) {
alert(textStatus);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
});
But I am getting this particular error:
XMLHttpRequest cannot load . No 'Access-Control-Allow-Origin' header
is present on the requested resource. Origin 'http://localhost:8383'
is therefore not allowed access. The response had HTTP status code
403.
Please help to solve this...
While setting up database server you have to whitelist the ip that may access it explicitly or add * so that all ip may access it.
By default Neo4j only accept request from localhost.
Do you have change param org.neo4j.server.webserver.address in neo4j-server.properties ?
Do you have access to the browser ?
Moreover, you don't use the good endpoint : change http://blackswantechnologiesosint.sb04.stations.graphenedb.com:24789/browser/ by http://blackswantechnologiesosint.sb04.stations.graphenedb.com:24789/db/data/transaction/commit`
See the documentation on this : http://neo4j.com/docs/stable/rest-api.html
Is there any possibility to call "WSDL" method in cloud code ?
for example, there is a "WSDL" web service and i want to check if there is an new data in it and if there is i want to send push notification to user. I got the logic, but i could not find any information about "WSDL" in parse.com documentation.
this didn't help:
Parse.Cloud.httpRequest({
url: 'https://services.rs.ge/WayBillService/WayBillService.asmx',
params: {
su : 'test1'
},
success: function(httpResponse) {
console.log(httpResponse.text);
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
}
});
Sure you can, now, first we need to get a few things straight.
WSDL is just the definition of the services "Web Services Description Language"
You are talking SOAP here "Simple Object Access Protocol"
If you go to https://services.rs.ge/WayBillService/WayBillService.asmx in your browser, you will se a list of methods/SOAPActions that are available to you and if you click them, you will see an example of how to call the method.
For example, get_server_time, https://services.rs.ge/WayBillService/WayBillService.asmx?op=get_server_time
Example how to call get_server_time:
Parse.Cloud.job('soap', function(request, status) {
var Buffer = require('buffer').Buffer,
buffer = new Buffer(
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">' +
' <soap12:Body>' +
' <get_server_time xmlns="http://tempuri.org/" />' +
' </soap12:Body>' +
'</soap12:Envelope>'
);
Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://services.rs.ge/WayBillService/WayBillService.asmx',
headers: {
'Content-Type': 'text/xml; charset=utf-8'
},
body: buffer,
success: function(httpResponse) {
status.success(httpResponse.text);
},
error: function(httpResponse) {
status.error('Request failed with response code ' + httpResponse.status);
}
});
});