I don't know how to pass the --user field of this curl request in vue-apollo
curl -v \
--user 'user#domain.com:password' \
-X POST \
-H "Content-Type: application/json" \
--data '{ "query": "{ companies{ uid name url }}" }' \
http://localhost:4000/graphql
where in vue-apollo can I set --user ?
I've tried in vue-apollo options object the following
const defaultOptions = {
// You can use `https` for secure connection (recommended in production)
httpEndpoint,
wsEndpoint: null,
persisting: false,
websocketsOnly: false,
ssr: false,
getAuth: () => `Basic user#domain.com:password`
};
but it doesn't work
I'm expecting the companies results
{
"data": {
"companies": [
{
"id": "someId",
"name": "Facebook",
"url": "facebook.com"
},
{
"id": "someId",
"name": "Twitter",
"url": "twitter.com"
}
]
}
}
The getAuth method in defaultOptions should return the encoded Basic authentication
getAuth: () => `Basic ZrT2mWt3gJKHRJ33tf20hJrq==`
const defaultOptions = {
// You can use `https` for secure connection (recommended in production)
httpEndpoint,
wsEndpoint: null,
persisting: false,
websocketsOnly: false,
ssr: false,
getAuth: () => `Basic ZrT2mWt3gJKHRJ33tf20hJrq==`
};
Related
I'm trying to fetch Wise API to save the exchange rate to Google Sheets, but for some reason the data returned is not correct.
It works in Postman but when I make same request in Google Sheets via Google Apps Script data just don't match.
curl example from documentation
https://api.transferwise.com/v3/quotes/ \
-H "Authorization: Bearer <your client credentials token>"
-H 'Content-type: application/json' \
-d '{
"sourceCurrency": "GBP",
"targetCurrency": "USD",
"sourceAmount": null,
"targetAmount": 110 }'
Response in Postman:
Request in Google Apps Script:
const url = "https://api.transferwise.com/v3/quotes/";
const response = UrlFetchApp.fetch(url, {
"method": "POST",
"headers": {
"Authorization": "Bearer + mytoken",
"Content-Type": "application/json"
},
"muteHttpExceptions": true,
"followRedirects": true,
"validateHttpsCertificates": true,
"contentType": "application/json",
"payload": JSON.stringify({"\\\"sourceCurrency\\\"":"\\\"EUR\\\"","\\\"targetCurrency\\\"":"\\\"USD\\\"","\\\"sourceAmount\\\"":"null","\\\"targetAmount\\\"":"1000"})
});
const data = JSON.parse(response.getContentText())
Logger.log("Response code is %s", response.getResponseCode());
Logger.log(data.rate);
}
Response on console:
API is returning "1.0176" instead of "0.98015" and I can't discovery what I'm doing wrong.
Change your payload to:
"payload": `{
"sourceCurrency": "EUR",
"targetCurrency": "USD",
"souceAmount": 1000,
"targetAmount": null
}`
Im trying to make this api POST request to view.publish endpoint on slack api
As the documentation explains, im using the token and user_id in params, but i dont know what do i need to do with the view param
i set "application/json;charset=UTF-8" as content-type in the headers and on the body the JSON of the payload i want to publish:
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This is a section block with a button."
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Click Me",
"emoji": true
},
"value": "click_me_123",
"url": "http://scoreboard-azureslackbot-salvosoftware.s3-website.us-east-2.amazonaws.com/",
"action_id": "button-action"
}
}
]
}
This error is displayed when i make that api call:
{
"ok": false,
"error": "invalid_arguments",
"response_metadata": {
"messages": [
"[ERROR] failed to match all allowed schemas [json-pointer:/view]",
"[ERROR] must provide an object [json-pointer:/view]",
"[ERROR] must provide an object [json-pointer:/view]"
]
}
}
Documentation says that view must be a JSON-encoded string
Also this warning is displayed in the body tab:
This answer is from Aubrey, support team in slack.
No params needed.
In the Authorization tab you need beared authorization.
On the body you need to set is as raw -> JSON and this would be your JSON:
{
"user_id": {{YOUR_USER_ID}},
"view": {
"type": "home",
"blocks": [
{
{{YOUR_PAYLOAD}}
}
]
}
}
It helped me basing on this CURL command
curl -L -X POST 'https://slack.com/api/views.publish' \
-H 'Content-type: application/json' \
-H 'Authorization: Bearer {{YOUR TOKEN}}' \
--data-raw '{
"user_id": {{YOUR USER ID}},
"view": {
"type": "home",
"blocks": [{
{{YOUR PAYLOAD}}
}]
}
}'
I'm trying to send a notification from flutter application directly, but I can not figure it out how to do it.
Everywhere they say have to send a curl request with basic network library but there is no example.
DATA='{"notification": {"body": "this is a body","title": "this is a title"}, "priority": "high", "data": {"click_action": "FLUTTER_NOTIFICATION_CLICK", "id": "1", "status": "done"}, "to": "<FCM TOKEN>"}'
curl https://fcm.googleapis.com/fcm/send -H "Content-Type:application/json" -X POST -d "$DATA" -H "Authorization: key=<FCM SERVER KEY>"
Please help me with an example in DART.
You could try this:
import 'dart:async';
import 'dart:convert' show Encoding, json;
import 'package:http/http.dart' as http;
class PostCall {
final postUrl = 'https://fcm.googleapis.com/fcm/send';
final data = {
"notification": {"body": "this is a body", "title": "this is a title"},
"priority": "high",
"data": {
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"id": "1",
"status": "done"
},
"to": "<FCM TOKEN>"
};
Future<bool> makeCall() async {
final headers = {
'content-type': 'application/json',
'Authorization': 'key=<FCM SERVER KEY>'
};
final response = await http.post(postUrl,
body: json.encode(data),
encoding: Encoding.getByName('utf-8'),
headers: headers);
if (response.statusCode == 200) {
// on success do sth
return true;
} else {
// on failure do sth
return false;
}
}
}
putenv('GOOGLE_APPLICATION_CREDENTIALS=../platform-engineering.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes(array("https://www.googleapis.com/auth/bigquery",
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloudplatform.read-only"
));
$http = $client->authorize();
$body = '{"dataSourceId": "adwords","destinationDatasetId": "adwords","displayName": "testing","params": {"customer_id": "42342423432"}, "dataRefreshWindowDays": 3,"disabled": false, "datasetRegion":"US"}';
$resp = $http->request("POST", "https://content-bigquerydatatransfer.googleapis.com/v1/projects/platform-engineering/transferConfigs", [
'body' => $body,
'headers' => array('content-type' => 'application/json')
]);
print_r($resp->getBody()->getContents());
Response as below :
{ "error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT" } }
CURL command-line not working either:
curl -H "Content‐Type: application/json" -H "Authorization: Bearer MY_TOKEN" -d '{"dataSourceId": "adwords","destinationDatasetId": "adwords","displayName": "mauliktestng","params": {"customer_id": "4729344234"}}' https://bigquerydatatransfer.googleapis.com/v1/projects/platform-engineering/transferConfigs
Try replacing body to this:
$body = '{"dataSourceId": "adwords","destinationDatasetId":
"adwords","displayName": "testing","params": {"fields": {"key":
"customer_id", "value": {"string_value": "42342423432"}}},
"dataRefreshWindowDays": 3,"disabled": false, "datasetRegion":"US"}';
I'm trying to create an index within a set under a specific namespace, but am unsure how to do it.
My resources have this as an HTTP example:
POST /example/v1/index/{namespace}/{set}/{indexName}
and for an example input:
{
"fields": [
{ "indexField": "firstName", "indexReverseOrder": true },
{ "indexField": "lastName" }
],
"options": {
"isUnique": true
}
}
this consumes
application/json;charset=UTF-8
but when I write this out as
curl -X POST exampleurl.com/example/v1/index/example_namespace/example_set/example
set -d " {
"fields": [
{ "indexField": "firstName", "indexReverseOrder": true },
{ "indexField": "lastName" }
],
"options": {
"isUnique": true
} }" -H "Content-type : application/json;charset=UTF-8"
I get the following HTTP status code
HTTP/1.1 415 Unsupported Media Type
Can anyone explain to me what's going on and how I might fix this? Also, let me know if you don't have enough information about the API to understand it, thanks!
EDIT:
As some sort of a reference, for this API when I create a set in a namespace I do:
curl -X POST http://exampleurl.com/example/v1/store/example_namespace -d "example_set" -H "Content-type: application/json;charset=UTF-8"
and this is successful. I thought indexes would be similar to this, but apparently not.
The error is due to the bash shell misinterpreting the double quotes before the json
curl -X POST exampleurl.com/example/v1/index/example_namespace/example_set/example
set -d " {
"fields": [
{ "indexField": "firstName", "indexReverseOrder": true },
{ "indexField": "lastName" }
],
"options": {
"isUnique": true
} }" -H "Content-type : application/json;charset=UTF-8"
should be:
curl -X POST exampleurl.com/example/v1/index/example_namespace/example_set/example
set -d ' {
"fields": [
{ "indexField": "firstName", "indexReverseOrder": true },
{ "indexField": "lastName" }
],
"options": {
"isUnique": true
} }' -H "Content-type : application/json;charset=UTF-8"
The difference is the single quotes encapsulating the json. The bash shell will give an error in trying to execute the command.
You have a typo in your media type:
application/json;charset=UTF=8
Should be:
application/json;charset=UTF-8