JSON API .Net Core Put and Patch Examples - rest

I am testing boilerplate library for dotnet core with json:api specification from github repo {json:api}. The endpoints for GET (with or without query), POST & DELETE are working as expected when I send from postman. But I couldn't find working examples to change the existing resource with PUT or PATCH. When i send patch request with data, it give me back response "200 OK" but it didn't change in database. Below are my request and response.
Request GET : http://localhost:5000/api/people -> 200 OK
Response : [
{
"name": "Samuel",
"articles": null,
"id": 2,
"stringId": "2"
},
{
"name": "John",
"articles": null,
"id": 3,
"stringId": "3"
},
{
"name": "Robbin",
"articles": null,
"id": 4,
"stringId": "4"
} ]
Request GET: http://localhost:5000/api/people/2 -> 200 OK
Response : {
"name": "Samuel",
"articles": null,
"id": 2,
"stringId": "2"
}
Request GET: http://localhost:5000/api/people/2?include=articles -> 200 OK
Response : {
"name": "Samuel",
"articles": [],
"id": 2,
"stringId": "2"
}
Request POST: http://localhost:5000/api/people -> 201 Created
Request Body: {"name":"Samuel"}
Response : {
"name": "Samuel",
"articles": null,
"id": 2,
"stringId": "2"
}
Request DELETE: http://localhost:5000/api/people/2 -> 204 No Content
How can I update data?

I made a final decision after reading specification documents of JSONAPI and OData. I will just stick to my own format for better understanding of my own code and I recommend Swagger for Api Documentation. It doesn't make sense if the spec doesn't meet my requirement even when people are telling it's the standard.

I found in documents that require to includes following two headers for different api calls and body request is also different for PATCH.
"Accept: application/vnd.api+json" <--- This needs to put in header
"Content-Type: application/vnd.api+json" <--- This also needed.
Request PATCH: http://localhost:5000/api/people/3 -> 200 OK
// Request body becomes text, anybody knows how to format to JSON?
Request Body(Text): {
"data": {
"type": "people",
"attributes": {
"name": "John"
}
}
}
Response : {
"data": {
"attributes": {
"name": "John"
},
"relationships": {
"articles": {
"links": {
"self":
"http://localhost:5000/api/people/3/relationships/articles",
"related": "http://localhost:5000/api/people/3/articles"
}
}
},
"type": "people",
"id": "3"
} }

Related

How I can create payment document in FlowPay

According to document I am testing API using Insomnia. Generating a payment document is a single operation that I have used a single POST call to the intended document endpoint
create, for example:
POST https://app.sandbox-new.flowpay.it/api/:tenantID/invoices
Content-Type: application/json
Authorization: Bearer <accessToken>
Body:
{
"attachments": null,
"currency": "EUR",
"date": "2022-08-23T17:32:28Z",
"items": [
{
"amount": 123.12,
"description": "hello",
"quantity": 1
}
],
"number": "123465",
"recipientIban": null,
"recipientVat": "132412341",
"senderIban": null,
"senderVat": "23412341245",
"terms": [
{
"amount": 123.12,
"description": "hello",
"expire": "2022-08-25T17:32:28Z",
"information": "hello",
"method": null,
"recurringInfo": null
}
]
}
To get :tenantID I have followed flowpay documentation
But I am getting not authorized to upload this invoice error message.
{
"errorDescription": "not authorized to upload this invoice",
"code": 2003,
"statusCode": 401,
"requestID": "1FAF3537-FA0B-4642-AF75-94FE9FDC8E2A",
"service": 2
}
Any body help me please. Thanks

Telegram: no answer sent with answerInlineQuery

I make a POST request in response to an inline request with the following url
https://api.telegram.org/bot<some-token>/answerInlineQuery
and body
{
"inline_query_id": "${inline_query_id}",
"result": {
"InlineQueryResultArticle": [
{
"type": "article",
"id": "111",
"title": "some-title",
"input_message_content": {"message_text": "TEXT 1"}
}
]
}
}
Telegram responds 200 OK but there is no changes/answers in the bot.
I've also tried so many modifications of the body to sent. No one was successfull, but no one error I`ve got too.
Finally, this one works.
{
"inline_query_id": "${inline_query_id}",
"results": [{
"type": "article",
"id": "111",
"title": "some-title",
"input_message_content": {"message_text":"TEXT 1" }
}]
}
It needs results instead of result. And no definition of InlineQueryResultArticle

How to create a jsonpath to instagram business account in a batch request with the Graph API?

My goal is to create a batch request with dependent calls as documented here:
https://developers.facebook.com/docs/graph-api/making-multiple-requests#operations
You can reference the results of a previous operation using JSONPath in form post parameters in addition to query string parameters.
I can't get the right JSONPath to make it work when there are multiple elements in the data array that have an instagram_business_account.id (iba_id)
The two calls that I want to make are
/me/accounts?fields=instagram_business_account
/17841400714813297?fields=business_discovery.username(thomasguntenaar){media_count}
my batch looks like
[
{"method":"GET","name":"get-ig", "relative_url":"me/accounts?fields=instagram_business_account"},
{"method":"GET", "relative_url":"{result=get-ig:$.data..instagram_business_account.id}?fields=business_discovery.username(thomasguntenaar){media_count}}"}
]
in the second query you are supposed to put the JSONPath to the instagram business account id
after result=
I get this error back
{
"code": 404,
"body": "{
\"error\": {
\"message\": \"(#803) Some of the aliases you requested do not exist: 17841400714813297,17841403388404550,17841401383243593\",
\"type\": \"OAuthException\",
\"code\": 803,
\"fbtrace_id\": \"FV8qA+oA7fp\"
}
}"
}
Facebooks json response after the first call is
{
"data": [
{
"id": "466912700123917"
},
{
"id": "502655553273897"
},
{
"instagram_business_account": {
"id": "17841400714813297"
},
"id": "503124266815195"
},
{
"instagram_business_account": {
"id": "17841403388404550"
},
"id": "510613645695833"
},
{
"instagram_business_account": {
"id": "17841401383243593"
},
"id": "2061834074114937"
}
],
"paging": {
"cursors": {
"before": "NDY2OTEyNzAwMTIzOTE3",
"after": "MjA2MTgzNDA3NDExNDkzNwZDZD"
}
}
}
When you query the second request like this
?ids=17841400714813297,17841403388404550,17841401383243593&fields=business_discovery.username(thomasguntenaar){username,media_count}
the response looks like this
{
"17841400714813297": {
"business_discovery": {
"username": "thomasguntenaar",
"media_count": 76,
"id": "17841400714813297"
},
"id": "17841400714813297"
},
"17841403388404550": {
"business_discovery": {
"username": "thomasguntenaar",
"media_count": 76,
"id": "17841400714813297"
},
"id": "17841403388404550"
},
"17841401383243593": {
"business_discovery": {
"username": "thomasguntenaar",
"media_count": 76,
"id": "17841400714813297"
},
"id": "17841401383243593"
}
}
(#803) Some of the aliases you requested do not exist: 17841400714813297,17841403388404550,17841401383243593
Apparently the API thinks this was supposed to be one id, and doesn’t realize it is supposed to be three separate ones.
The API has a syntax to request data for more than one object in one request - instead of /{id}?fields=foo, you can make a request of the form ?ids={1,2,3}&fields=foo, to request this data for the objects with ids 1, 2 and 3 in one go. The resulting data structure will contain a sub-structure for each of those ids.
The same structure should work in batch requests as well, when parts (here, the IG account ids returned by the previous query) are dynamically inserted.

Fetching multiple event details in Office 365

I need to fetch information related to eventId from office 365 for multiple events.
Is there a way I can get that info in a single REST call?
I want specific events only (based on eventId's only)
A batch request may be what you are looking for.
See json Batching Documentation for more information
Keep in mind that batching is currently limited to 20 requests per message (known issues)
Example:
You will need to send a POST Message to the batch endpoint
https://graph.microsoft.com/v1.0/$batch
inside the body you will need to include your requests:
Note: do not include the server url (https://graph.microsoft.com/v1.0/) in the url property or the request will fail with "BadRequest - Invalid request Uri".
Request-Body:
{
"requests": [
{
"id": "1",
"method": "GET",
"url": "/me/calendarview?startdatetime=2018-03-01T18:31:34.206Z&enddatetime=2018-03-12T18:31:34.206Z"
},
{
"id": "2",
"method": "GET",
"url": "/me/events/{someEventId}"
},
]
}
When the server has processed all requests an response array containing the results will be sent back:
Server-Response:
{
"responses": [
{
"id": "2",
"status": 200,
"headers": {
"OData-Version": "4.0",
"Content-Type": "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8",
"ETag": "W/\"Z+ICSvkiAfZX7XWQAZ6IH==\""
},
"body": {
// the event object
}
},
{
"id": "1",
"status": 200,
"headers": {
"OData-Version": "4.0",
"Content-Type": "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8"
},
"body": {
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('aUserID')/calendarView",
"value": [
// list of found event-objects
]
}
}
]
}

Facebook - Get All Messages from Page

Response from request for getting messages about specific conversation are returning just IDs from the all separate messages that are contained in that conversation. So, if I want to get all of the messages from all conversation, there will be a lot of request...
Are there any solution for getting all of the messages(text from messages) from specific conversation in one request? Or any other workaround for this kind of issue?
Here is the example:
Request: XXX?fields=subject,message_count,messages -> (where XXX are id of conversation)
Response:
{
"message_count": 4,
"id": "XXX",
"messages": {
"data": [
{
"created_time": "2016-05-11T08:29:56+0000",
"id": "id1"
},
{
"created_time": "2016-05-11T08:29:54+0000",
"id": "id2"
},
{
"created_time": "2016-05-11T08:21:56+0000",
"id": "id3"
},
{
"created_time": "2016-05-09T14:04:17+0000",
"id": "id4"
}
]
}
}
I suppose you are using the conversation details endpoint; have you tried using the /messages/edge of the same endpoint?
Try to rewrite your request as:
XXX/messages?fields=message,subject,to