Storage Transfer Service transferJobs.patch API does not work for nested object - google-api

Problem you have encountered:
Following steps at link below for transferJobs.patch API
https://cloud.google.com/storage-transfer/docs/reference/rest/v1/transferJobs/patch
Patch API works as expected if want to update description. Sample Below
Request:
{
"projectId": "<MY_PROJECT>",
"transferJob": {
"transferSpec": {
"objectConditions": {
"lastModifiedSince": "2022-01-24T18:30:00Z"
}
},
"description": "updated description"
},
"updateTransferJobFieldMask": "description"
}
Response: Success 200
Patch API do not work if want to update nested object field. Sample Below
{
"projectId": "<MY_PROJECT>",
"transferJob": {
"transferSpec": {
"objectConditions": {
"lastModifiedSince": "2022-01-22T18:30:00Z"
}
},
"description": "updated description"
},
"updateTransferJobFieldMask": "transferSpec.objectConditions.lastModifiedSince"
}
Response: 400
{"error": {
"code": 400,
"message": "Invalid path in the field mask.",
"status": "INVALID_ARGUMENT"}}
Tried other combinations following documentation/sample code reference but none of them work. Tried options as
transferSpec.objectConditions.lastModifiedSince
transferJob.transferSpec.objectConditions.lastModifiedSince
objectConditions.lastModifiedSince lastModifiedSince Snake case
combination referring to FieldMaskUtil as transfer_spec.object_conditions.last_modified_since
What I expected to happen:
Patch API to work successfully for nested object as per documentation I.e. "updateTransferJobFieldMask": "transferSpec.objectConditions.lastModifiedSince"

updateTransferJobFieldMask works on the top level object, in this case transferSpec.
Changing that line to updateTransferJobFieldMask: transferSpec should work.
From the documentation:
The field mask of the fields in transferJob that are to be updated in this request. Fields in transferJob that can be updated are: description, transfer_spec, notification_config, and status. To update the transfer_spec of the job, a complete transfer specification must be provided. An incomplete specification missing any required fields will be rejected with the error INVALID_ARGUMENT.

Providing complete object having required child field worked. Sample example for future reference to other dev.
Below job transfer dat from Azure to GCP bucket and during patch updating last modified time. Both transfer_spec and transferSpec works as updateTransferJobFieldMask.
{
"projectId": "<MY_PROJECT>",
"updateTransferJobFieldMask": "transfer_spec",
"transferJob": {
"transferSpec": {
"gcsDataSink": {
"bucketName": "<BUCKET_NAME>"
},
"objectConditions": {
"lastModifiedSince": "2021-12-30T18:30:00Z"
},
"transferOptions": {},
"azureBlobStorageDataSource": {
"storageAccount": "<ACCOUNT_NAME>",
"container": "<CONTAINER>",
"azureCredentials": {
"sasToken": "<SAS TOKEN>"
}
}
}
}
}

Related

Use Postman to test Appsync Subscription

I have been able to successfully execute Appsync GraphQL queries and mutations from Postman. However, i'm struggling to connect to subscriptions which are websocket urls.
How can I achieve the same ?
Since Postman supports WebSockets testing GraphQL subscriptions is achievable as well. Such a testing requires two steps:
connection to a server,
sending a start message.
Establishing a connection:
Create a new WebSocket request.
Put your server URL ws:// or wss://.
Add custom header parameter Sec-WebSocket-Protocol: graphql-ws. Other headers may depend on your server configuration.
Press the "Connect" button.
When the connection is established we may start a subscription.
In the "New message" field put the command.
Press the "Send" button.
The start message should look like this:
{
"id":"1",
"payload": {
"operationName": "MySubscription",
"query": "subscription MySubscription {
someSubscription {
__typename
someField1
someField2 {
__typename
someField21
someField22
}
}
}",
"variables": null
},
"type": "start"
}
operationName is just the name of your subscription, I guess it's optional. And someSubscription must be a subscription type from your schema.
query reminds regular GraphQL syntax with one difference:
__typename keyword precedes every field list.
For example, the query from the payload in regular syntax looks like the following:
subscription MySubscription {
someSubscription {
someField1
someField2 {
someField21
someField22
}
}
}
Example message with parameters (variables):
{
"id":"1",
"payload": {
"operationName": "MySubscription",
"query": "subscription MySubscription($param1: String!) {
someSubscription((param1: $param1)) {
__typename
someField
}
}",
"variables": {
"param1": "MyValue"
}
},
"type": "start"
}
It also reminds regular GraphQL syntax as described above.
variables is an object with your parameters.
#Vladimir's answer is spot on. Adding a few notes for folks still having trouble.
Full document here # https://docs.aws.amazon.com/appsync/latest/devguide/real-time-websocket-client.html
Step 1 - establish connection:
make sure to base64 encode values in "header" and "payload" querystrings
header example:
{
"host":"example1234567890000.appsync-api.us-east-1.amazonaws.com",
"x-api-key":"da2-12345678901234567890123456"
}
payload: You can pass in empty payload
{}
Step 2 - register subscription:
Include the authorization in the message. Escape line feeds properly "\n" throws an error but "\\n" works. it throws the following error - misleading.
Don't forget to stringify value in "data" field.
{
"type": "error",
"payload": {
"errors": [
{
"errorType": "UnsupportedOperation",
"message": "unknown not supported through the realtime channel"
}
]
}
}
{
"id": "2",
"payload": {
"data": "{\"query\":\"subscription onCreateMessage { changeNotification{ __typename changeType from } }\",\"variables\":{}}",
"extensions":{
"authorization":{
"host":"example1234567890000.appsync-api.us-east-1.amazonaws.com",
"x-api-key":"da2-12345678901234567890123456"
}
}
},
"type": "start"
}

When I send a mutation request to chaskiq graphql endpoint I get "Data not found"

I have been using Chaskiq for some work but ran into an error.
I built from source on Ubuntu 20.04.
I got the graphql part working and query requests work. However, whenever I make a mutation request I seem to get this response:
{
"errors": [
{
"message": "Data not found",
"data": {}
}
]
}
Example mutation request I sent to get the response above:
mutation updateAppUser($appKey: String!, $options: Json!, $id: Int!) {
updateAppUser(appKey: $appKey, options: $options, id: $id) {
appUser {
id
name
email
}
}
}
I have the variables Query Variables as below:
{
"appKey": <My_APP_KEY>,
"options": {
"name": <Custom_Name>
},
"id": <My_ID>
}
Please help me know the solution to the problem.
Data not found is returned when the server does not found any record.
basically ActiveRecord::RecordNotFound , so you are probably trying to find the wrong record. check the logs to see what's happening

Insert more than one record using GraphQL Mutation

I would like to insert more than one record using GraphQL Mutation but it is giving error. here is the code which I have used to perform this.
input BusinessImageInput {
business_id: Int
image_url: String
}
mutation MyMutation($images: [BusinessImageInput!]) {
insert_business_images(objects: [$images]) {
affected_rows
}
}
And here is variable which i want to pass as paramter.
{"images": [
{
"business_id": 15,
"image_url": "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTVzlb1cEw8E0LeLJzk9c0OQV-N387Nt2Kn5w&usqp=CAU"
},
{
"business_id": 15,
"image_url": "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTVzlb1cEw8E0LeLJzk9c0OQV-N387Nt2Kn5w&usqp=CAU"
}
]
}
Here is the error
{
"errors": [
{
"extensions": {
"path": "$.query",
"code": "bad-request"
},
"message": "not a valid GraphQL query"
}
]
}
Please help me out.
There is one glaring issue in your code. This line
insert_business_images(objects: [$images]) {
should be
insert_business_images(objects: $images) {
Notice the removed square brackets.
If that does not help, then we'll need more information, such as:
what error do you get?
which implementation of GraphQL are you using both client-side and server-side?
what does the GraphQL code (and possibly resolvers) look like on the server? You have only given us the client-side of the equation.
It's as simple as
mutation MyMutation($images: [BusinessImageInput!]) {
insert_business_images(images: $images) {
or
mutation MyMutation($objects: [BusinessImageInput!]) {
insert_business_images(objects: $objects) {
depends on server insert_business_images mutation definition, the name of argument (images or objects ?) - use explorer ... and [as you can see above] usually input arg and variable are same-named, they only differs with $ prefix.
https://graphql.org/learn/queries/#variables
Also you must follow server input types.

Problem with create team with Microsoft Graph Api

I have a problem with creating teams using the Microsoft Graph Api. I can get/create groups but when I try to get/create teams I get an error. I'm using postman and the group has owners and members, just as the documentation of MS, also has the permissitions it asks for groups. If somebody can help me, cause I look everywhere for a same error but no found it.
PUT https://graph.microsoft.com/v1.0/groups/{id}/team
Headers: Authorization: bearer token and content-type: json
Body is
{
"memberSettings": {
"allowCreateUpdateChannels": true
},
"messagingSettings": {
"allowUserEditMessages": true,
"allowUserDeleteMessages": true
},
"funSettings": {
"allowGiphy": true,
"giphyContentRating": "strict"
}
}
I always get the same error
{
"error": {
"code": "BadGateway",
"message": "Failed to execute backend request.",
"innerError": {
"request-id": "45eeba8a-9d35-45e8-b42e-c60da7a47dde",
"date": "2020-01-23T21:55:44"
}
}
}
According to the Graph API docs for this, you're not calling the correct endpoint to create a new Team. It should be
POST https://graph.microsoft.com/beta/teams
and a payload similar to
Content-Type: application/json
{
"template#odata.bind": "https://graph.microsoft.com/beta/teamsTemplates('standard')",
"displayName": "My Sample Team",
"description": "My Sample Team’s Description",
"owners#odata.bind": [
"https://graph.microsoft.com/beta/users('userId')"
]
}
Note that it's slightly different, as per the docs, whether you're using delegated versus application permissons.

Cannot load search template registered with REST API

I have a problem when loading a search template which has been registrered through the REST API. If the search template is placed in the /config/scrips/ folder there is no problem.
The template has been registrered via POST to: /_search/template/templateName, and I can see that the template has been succesfully registered when I do a GET to: /_search/template/templateName.
However, when I try to send a request that utilizes this search template I get an error. If have tried the following endpoints:
POST: /_search/template (the one from the documentation)
POST: [index]/_search/template
POST: [index]/[type]/_search/template
With this body:
{
"template": {
"file": "templateName"
},
"params": {
"userId" : "AU43nSoTZOSzwq_2ZUA4",
etc...
}
}
But it keeps returning this error:
{
"error": "SearchPhaseExecutionException[Failed to execute phase [query_fetch], all shards failed; shardFailures {[UDBaJWKqQ5GpZedzLCtrFg][.scripts][0]: ElasticsearchIllegalArgumentException[Unable to find on disk script templateName]}]",
"status": 400
}
I cannot upload files to the ElasticSearch host that I'm using, so I need to register them via POST request. What am I missing?
Thanks in advance
The correct search request is like this:
GET /some_index/_search/template
{
"template": {
"id":"templateName"
},
"params": {
"userId" : "AU43nSoTZOSzwq_2ZUA4",
...
}
}

Resources