I'm using validation of user's in app purchase with google API:
Purchases.products: get
https://developers.google.com/android-publisher/api-ref/purchases/products/get
In C# on the backend I create HttpWebRequest with this url:
var url = string.Format("https://www.googleapis.com/androidpublisher/v2/applications/{0}/purchases/products/{1}/tokens/{2}", packageName, androidProductId, token);
var request = HttpWebRequest.Create(url);
request.Method = "GET";
The parameters packageName, productId and token, were set correctly.
After I send the request, google answers me with the next JSON object:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
So, the problem is about authorization my backend server. How could this be fixed?
I use IAP for authorization on backend server. Please read this article(russian language).
Related
I have hit a bit of a brick wall here. I am working in client side c# code and using the firestore API. I cannot post a document (with data) in. I am able to create a document by removing the line ".AddJsonBody(testdata)" below.
CODE
string url = "https://firestore.googleapis.com/v1/projects/<MYPROJECT>/databases/(default)/documents/Users";
var client = new RestClient(url);
string testdata = "{\"foo\":\"bar\"}";
var request = new RestRequest()
.AddJsonBody(testdata);
var response = await client.ExecutePostAsync(request);
ERROR
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name "foo" at 'document': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document",
"description": "Invalid JSON payload received. Unknown name "foo" at 'document': Cannot find field."
}
]
}
]
}
}
I have tried using document:commit. I have tried various different methods of parsing the data, all keep getting similar errors.
I am trying to consume Microsoft Dynamics Business Central Rest API, to create item using following endpoint:
https://api.businesscentral.dynamics.com/v1.0/mydomain.com/api/v1.0/companies({id})/items
Following is my code:
string requestBody = JsonConvert.SerializeObject(itemBodyValues);
string url = "https://api.businesscentral.dynamics.com/v1.0/mydomain.com/api/v1.0/companies({id})/items";
string encodedCredentials = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(userName + ":" + WebServiceAccessKey));
HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create(url);
endpointRequest.ContentType = "application/json";
endpointRequest.Method = "POST";
//endpointRequest.Accept = "application/json;odata=verbose";
using (var streamWriter = new StreamWriter(endpointRequest.GetRequestStream()))
{
streamWriter.Write(requestBody);
}
endpointRequest.Headers.Add("Authorization", "Basic " + encodedCredentials);
HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
Following is the request body (copied it from here):
{
"number": "1896-S",
"displayName": "ATHENS Desk",
"type": "Inventory",
"blocked": false,
"baseUnitOfMeasure": {
"unitCode": "PCS", //Unit of measure with this code exists in dynamics BC
"unitName": "Piece",
"symbol": "",
"unitConversion": null
},
"gtin": "",
"itemCategory": {
"categoryId": "TABLE", //Item category with this code exists in dynamics BC
"description": "Assorted Tables"
},
"inventory": 0,
"unitPrice": 1000.8,
"priceIncludesTax": false,
"unitCost": 780.7,
"taxGroupCode": "FURNITURE"
}
When i try to execute the code, then at endpointRequest.GetResponse(); i get the following error:
The remote server returned an error: (400) Bad Request.'
I tried creating item in postman (basic authentication), with same URL and request body and error is:
{
"error": {
"code": "BadRequest",
"message": "Does not support untyped value in non-open type. CorrelationId: 4bc23d7b-f6b3-4eca-ab62-6fb7d37e23ac."
}
}
It is important to note that item successfully gets created when i exclude baseUnitOfMeasure and itemCategory properties from request body. But including these properties causes the error. As i researched for the issue above, from different sources i found that, such issue appears when a field/property is mistyped. I am copying the request body from Microsoft document as mentioned above so i am clueless that which field is causing the issue. Please help me resolve this. Thanks
For Future visitors/readers:
It took some R&D to let me know that the request body that can be found in Microsoft Document actually contains some wrong property name.
we can go to https://api.businesscentral.dynamics.com/v1.0/[your domain]/api/v1.0/$metadata where after authentication we get the XML that specifies the property names that should be used. So, the request body that i found working is:
{
"number": "1836-S",
"displayName": "ATHENS Desk",
"type": "Inventory",
"blocked": false,
"baseUnitOfMeasure": {
"code": "PCS",
"displayName": "Piece",
"symbol": "",
"unitConversion": null
},
"gtin": "",
"itemCategory": {
"code": "TABLE", //make sure item category with this code doesn't already exists
"displayName": "Assorted Tables"
},
"inventory": 0,
"unitPrice": 1000.8,
"priceIncludesTax": false,
"unitCost": 780.7,
"taxGroupCode": ""
}
BadRequest is usually a bad datatype or json that is in the request body is not what is expected by the server side. I don't recommend adding any fields to the request body that are null this can also cause bad request.
My question is where is the field weight or net_weight on the item card to update via the rest api? Do you have to build a custom api just to include a field in the table not visible in the api to update?
I am using RestSharp to push an invoice to MYOB.
RestClient myobPostInvoicesClient = new RestClient("https://api.myob.com/");
RestRequest myobPostInvoicesRequest = new RestRequest("au/essentials/businesses/" + business_uid + "/sale/invoices", Method.POST);
myobPostInvoicesRequest.AddHeader("Authorization", "Bearer " + access_token);
myobPostInvoicesRequest.AddHeader("x-myobapi-key", clientId);
myobPostInvoicesRequest.AddHeader("x-myobapi-version", "v0");
myobPostInvoicesRequest.AddHeader("Content-Type", "application/json");
The JSON I am sending to the endpoint is as below
{{
"contact": {
"uid": "26939970"
},
"invoiceNumber": "IV00000000082",
"issueDate": "2020-06-07T09:00:00",
"dueDate": "2020-07-07T09:00:00",
"gstInclusive": "true",
"status": "Open",
"lines": [
{
"unitOfMeasure": "Qty",
"quantity": 5.0,
"unitPrice": 1000.0,
"total": 5000.0,
"taxType": {
"uid": "10"
},
"account": {
"uid": "9"
},
"description": "Test Description"
}
]
}}
The Response I am getting back from the MYOB Invoice API endpoint is
"{\"errors\":[{\"field\":\"\",\"message\":\"Forbidden\",\"code\":\"403\"}]}"
The access token and client id are both valid and I am following the structure of the Invoice based on the below link
https://developer.myob.com/api/essentials-accounting/endpoints/sale/invoices/
The ones I have included in the request where the fields that were previously marked as required but MYOB have modified the UI.
Just for reference I can GET contacts, accounts and taxtypes from MYOB, just getting the Forbidden 403 message back trying to POST an Invoice.
Any help you could provide would be very much appreciated.
If you are getting 403 Forbidden, you need to check the permissions on the account that you are using to make the post call.
See here to read about the permissions of the account
Except from link above
How do I check a user's access permissions
To find out exactly what rights the current user has, and to ensure they have the right permissions for your application to function correctly make a GET request to the {{company_file_uri}}/{{company_file_id}}/CurrentUser endpoint.
Following response tells you what permissions the user has on each url
{
"UserAccess": [
{
"ResourcePath": "https://{{company_file_uri}}/{{company_file_id}}/Banking/BankAccount/",
"Access": [
"GET"
]
},
{
"ResourcePath": "https://{{company_file_uri}}/{{company_file_id}}/Banking/ReceiveMoneyTxn/",
"Access": [
"GET",
"POST",
"PUT",
"DELETE"
]
},
...
]
}
My code below using Google Drive API v3 to transfer ownership from one user to another in the same domain is throwing this exception. I am using Service Account with domain-wide permissions for authorization piece.
string FileID = "xxxxxxxxxxxxxxxxxxx";
var getRequest1 = OwnerDrive.Files.Get(FileID);
getRequest1.Fields = "owners,name,parents,mimeType,permissions";
var afile = getRequest1.Execute();
foreach (var perm in afile.Permissions)
{
Console.WriteLine(perm.EmailAddress + " : " +
perm.DisplayName + " : " + perm.Role + " : " + perm.Id);
}
// I manually note down the permissionID of the current owner as
"14016095883385444520"
//Set New owner
Permission p = new Permission();
p.Role = "owner";
p.Type = "user";
p.EmailAddress = "newowner#xyz.com";
var updateRequest = OwnerDrive.Permissions.Update(p, FileID,
"14016095883385444520");
updateRequest.TransferOwnership = true;
updateRequest.Execute();
The error\exception throw is this:
"Message[The resource body includes fields which are not directly writable.] Location[ - ] Reason[fieldNotWritable] Domain[global]".
The new drive v3 API says to use Permissions.Update and pass it permissionID which I am doing (although manually). What am I missing here ? Any help is greatly appreciated.
I think you have hit bug.
I have been testing this with the Google Apis explorer
PATCH https://www.googleapis.com/drive/v3/files/1f3eFRpZM-NAID42B9DPwUOKr6nvXuIxnfVvlQ8H1pNc/permissions/06030588225573437243?transferOwnership=true&key={YOUR_API_KEY}
{
"emailAddress": "xxx#gmail.com"
}
Response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "The permission role field is required.",
"locationType": "other",
"location": "permission.role"
}
],
"code": 400,
"message": "The permission role field is required."
}
}
Request attempt two
PATCH https://www.googleapis.com/drive/v3/files/1f3eFRpZM-NAID42B9DPwUOKr6nvXuIxnfVvlQ8H1pNc/permissions/06030588225573437243?transferOwnership=true&key={YOUR_API_KEY}
{
"emailAddress": "xxx#gmail.com",
"role": "owner"
}
Response
{
"error": {
"errors": [
{
"domain": "global",
"reason": "fieldNotWritable",
"message": "The resource body includes fields which are not directly writable."
}
],
"code": 403,
"message": "The resource body includes fields which are not directly writable."
}
}
Bug report made here issue 73634062
I try send the message using the followingcode:
//...
FacebookClient fbClient = new FacebookClient(appId, appSecret);
fbClient.AccessToken = "...";
string to = "user id";
dynamic result = fbClient.Post(String.Format("{0}/feed", to), parameters);
but how I can know if the menssage has send to user successfully? what's the returns on case success/erros? I not found some details in the documentation of facebook-sdk-api for C#.
.NET version: v4.0.30319
Facebook Assembly version: 5.2.1.0
Thanks in advance.
by taking reference https://developers.facebook.com/docs/reference/rest/stream.publish/
you will have post_id for result parameter for successfull call, if fail it should be some json including error message, for example:
{
"error_code": 200,
"error_msg": "The user hasn't authorized the application to perform this action",
"request_args": [
{
"key": "method",
"value": "stream.publish"
},
{
"key": "access_token",
"value": "AAAC9okD6ZA7ABABhvJOZBQvUE2OsuHLKEkqlvKKkPDNB9kHfF55DqgKF2raHmSaUSgkpvLtgWniM5CFnu5mxaGODLqvwVz9zBNd1Jd6AZDZD"
},
{
"key": "format",
"value": "json"
}
]
}