Bigquery data transfer service for adwords - google-bigquery

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"}';

Related

API does not return right data in Google Apps Script

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
}`

ASP.NET Core OData Batch works for get but not update (PATCH)

Using .NET Core 3.1 and Microsoft.AspNetCore.OData 8.0.4.
I've set up Batch on my API and it works if all the requests in the batch are GET.
But if I put any updates, it fails with an error I can't figure out.
Successful direct update:
curl --location --request PATCH 'https://localhost:44390/api/odata/TradeTypeSpread(8432C89B-6D71-48B2-9F40-0000190AD326)' \
--header 'ApiAccessKey: xxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
"Id":"8432C89B-6D71-48B2-9F40-0000190AD326",
"Spread": 3.0
}'
200 OK
{
"error": null,
"isSucceeded": true,
"id": null
}
Failed batch update:
curl --location --request POST 'https://localhost:44390/api/Odata/$batch' \
--header 'ApiAccessKey: xxx' \
--header 'Content-Type: application/json' \
--data-raw '{
"requests": [
{
"id": "1",
"method": "PATCH",
"url": "/api/odata/TradeTypeSpread(8432C89B-6D71-48B2-9F40-0000190AD326)",
"body": {
"Id": "8432C89B-6D71-48B2-9F40-0000190AD326",
"Spread": 3.0
}
}
]
}'
{
"responses": [
{
"id": "1",
"status": 400,
"headers": {
"content-type": "application/json; odata.metadata=minimal; odata.streaming=true",
"odata-version": "4.0"
},
"body": {
"error": {
"code": "",
"message": "The input was not valid.",
"details": [
{
"code": "",
"message": "The input was not valid."
}
]
}
}
}
]
}
Can anyone see what I'm doing wrong in the second sample?
Startup Code:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
var defaultODataBatchHandler = new DefaultODataBatchHandler();
defaultODataBatchHandler.MessageQuotas.MaxNestingDepth = 2;
defaultODataBatchHandler.MessageQuotas.MaxOperationsPerChangeset = 100;
services
.AddControllersWithViews(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
options.Filters.Add(typeof(ValidateModelStateAttribute));
})
.AddNewtonsoftJson(options => options.SerializerSettings.UseDefaultSettings(nullValueHandling: Newtonsoft.Json.NullValueHandling.Include))
.AddOData(opt => opt.AddRouteComponents(
"api/odata",
new ModuleOdataEntityDataModel().GetEntityDataModel(),
defaultODataBatchHandler)
.Select().Filter().Count().OrderBy().Expand().SetMaxTop(Convert.ToInt32(Configuration["OdataMaxPageSize"])))
.ConfigureApiBehaviorOptions(options =>
{
options.SuppressModelStateInvalidFilter = true;
});
Controller Code
public class TradeTypeSpreadController : ODataController
{
[EnableQuery]
public async Task<IQueryable<TradeTypeSpreadDto>> Get()
{
...
}
public async Task<IActionResult> Patch(Guid key, Delta<TradeTypeSpreadDto> detalTradeSpreadDto)
{
...
}
}
Thanks
Sam
Working batch update for OData in ASP Net Core might look like this:
[AcceptVerbs("PATCH", "MERGE")]
public async Task<IActionResult> Patch(
[FromODataUri] string key,
Delta<MyModel> patch)
{
var model = patch.GetInstance();
await _repository.Update(model);
// IQueryable
var res = _repository.GetAll().SingleOrDefault(x => x.Id == key);
return Updated(res);
}
And it expects "get single" to be available as well:
[EnableQuery]
public IActionResult Get(
[FromODataUri] string key)
{
var dataset = _salesAreaBandsRepository.GetAll();
return Ok(dataset.SingleOrDefault(x => x.Id == key));
}
And of course the GetEdmModel() has to be adjusted if you use compound key or other field as a key:
private static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
var entitySet1 = builder.EntitySet<MyModel>("MyModel");
entitySet1.EntityType.HasKey(entity => entity.OtherKey);
return builder.GetEdmModel();
}
And you have:
app.UseODataBatching();
Sometimes you also need to change AddRouteComponents:
AddRouteComponents("odata", GetEdmModel(),
new DefaultODataBatchHandler())

http request using json-pointer slack view.publish JSON-encoded string

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}}
}]
}
}'

what's the equivalent vue-apollo options of this curl request?

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==`
};

Flutter send notificiation from client app with curl

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;
}
}
}