I have been writing Web Services from a recent past, this is a sample success and error response.
error
{
"code": 1150,
"status": false,
"message": "API Student does not exist.",
"serverTime": "2013-11-29 09:47:52"
}
success
{
"code": 200,
"status": true,
"data": {
"id": 49
},
"serverTime": "2014-04-17 05:06:17"
}
With regards to returning errors I have a confusion, why do we always return one error code and one message, for example, when username and password is required as input params, say a blank request is made, so what I return is a error code 1100 and error message "Username is incorrect". I never return the whole list of errors, for example, in this case, two error message with two error codes should be sent so it saves end users data & time.
This is a sample of what I suggest?
{
"code": 1010,
"status": false,
"errors": [
{
"code": 1000,
"name": "Username invalid"
},
{
"code": 1001,
"name": "Password invalid"
},
{
"code": 1002,
"name": "Password not strong"
}
],
"serverTime": "2013-12-03 12:34:02"
}
Why is this not a good way to do? I have not seen this in either Twitter API or Facebook API.
Nobody can stop API designers to return multiple possible error responses. Decision is up to them only but in my opinion you should return most relevant error occurred from server side.
There can be many reasons behind it like below :
Unified Error Handling by all clients.
Most relevant error caused will help client more actually as he will not have to take care about all probabilistic error caused.
JSON structure simplicity. ( Error Array will be avoided. )
Related
I'm trying to insert a record using the Zoho API, and I keep receiving a cryptic INVALID_DATA error message.
I've tried using their sample code which, of course, produces another error. And the sample code they provide for running in Postman also produces an error.
Their docs are lacking and inconsistent, and nobody is getting back to me on their message boards, and I'm getting desperate as I need to have this done today. Can anyone see what I'm doing wrong?
This is what I'm submitting via Postman
{
"data": [
{
"Owner": {
"id": "3938209039489388001"
},
"Contact_Name": {
"id": "398129039938498309"
},
"Subject": "Test",
"Product_Details": [
{
"product": {
"id": "1234567"
},
"quantity": 1
}
]
}
]
}
This is the error response
{
"data": [
{
"code": "INVALID_DATA",
"details": {
"api_name": "product",
"index": 0,
"parent_api_name": "Product_Details"
},
"message": "invalid data",
"status": "error"
}
]
}
The solution was to POST a product first, then grab that product ID and insert it under Product_Details. This is not documented, so I assumed the product would be created automatically, which it wasn't.
Using PowerShell's Invoke-RestMethod, I have successfully been able to make a call to "https://graph.microsoft.com/beta/teams/{team-id}/channels/{channel-id}/chatThreads" to post a message to my desired Team/Channel in a very neatly formatted way.
What I am now struggling with is #mentioning a user in the same message. I've followed the short tutorial on https://myteamsday.com/2019/03/05/sending-message-with-atmention-onto-a-channel-using-graphapi/
I get to the point where I added the mentions section to the body of the request, complete with id of the user and id of the mention.
Once I make the call, the message is posted but only the text as show in the content property. No link/mention to the actual user.
{
"rootMessage": {
"body": {
"contentType": "html",
"content": "Hello, World! <at id=\"0\">Jack Black</at>"
},
"mentions": [ {
"id": 0,
"mentionText": "Jack Black",
"mentioned": {
"id": "ac5e5x81-39Dd-4748-beTa-b5cd6t93ba67",
"displayName": "Jack Black",
"userIdentityType": "aadUser"
}
}
]
}
}
Here's one thing I noticed in the tutorial though, the guy references "https://graph.microsoft.com/beta/teams/{team-id}/channels/{channel-id}/messages" , but Microsoft Graph references "https://graph.microsoft.com/beta/teams/{team-id}/channels/{channel-id}/chatThreads"
When I replace chatThreads with message in Microsoft Graph, I get an Bad Request error message complaining about the content property cannot be null, but it is NOT null.
EDIT 1:
When using https://graph.microsoft.com/beta/teams/{team-id}/channels/{channel-id}/messages on graph explorer
{
"error": {
"code": "BadRequest",
"message": "Value cannot be null.\r\nParameter name: Content",
"innerError": {
"request-id": "f0d4fed8-7726-4338-8a68-9685a690eab5",
"date": "2019-07-02T12:46:14"
}
}
}
You need to include entities, with type 'mention', in your message and the message of the text should include <at>username</at> for each entity mentioned.
I am attempting to run a facebook ad for our business and am getting an error message stating, "the payload attachment is invalid" when using a custom JSON code created inside ManyChat.
Here is the following code that facebook keeps rejecting:
[
{
"message": {
"attachment": {
"type": "template",
"payload": {
"template_type": "button",
"text": "Click \"Get Started\" down below to see how much your home
could sell for!",
"buttons": [
{
"type": "postback",
"payload":
"MANYCHATJSON(3384948)::ACT::2655bc1baaec206ec2a527fc090fd1da",
"title": "Get Started"
}
]
}
}
}
}
]
I had more text and emojis in the initial greeting but removed everything and still cannot proceed.
Any help would be appreciated.
Format your JSON for example here https://jsonformatter.curiousconcept.com/#
It will process your data into correct and then paste it into the Facebook page where you need it. In my case, it helped
P.S. after fixing error "the payload attachment is invalid" you could face with the next one "No promotion object found: Please specify a promoted object for the ad set". And here is how to fix it too
I'm trying to access oneDrive via Graph api, and when I hit the api, I get User's mysite not found.
GET https://graph.microsoft.com/beta/me/drive
{
"error": {
"code": "ResourceNotFound",
"message": "User's mysite not found.",
"innerError": {
"request-id": "13eb583d-c29a-42af-8868-bae06d554538",
"date": "2018-05-18T06:06:55"
}
}
}
So, looking out for the solution, I saw an issue where they said to get OneDrive for Business' location, But this returns UnauthorizedAccessException
GET https://graph.microsoft.com/beta/me?select=mySite
{
"error": {
"code": "-2147024891, System.UnauthorizedAccessException",
"message":
"Access denied. You do not have permission to perform this action or access this resource.",
"innerError": {
"request-id": "3489894e-faa0-42c6-9f3b-e76c4708ce15",
"date": "2018-05-18T06:10:00"
}
}
}
And when I hit for /me endpoint, there I see an empty array for provisionedPlans.
GET https://graph.microsoft.com/beta/me
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#users/$entity",
"id": "7e8397a6-b299-34a2-af06-d3487t5b5174",
//...
"onPremisesProvisioningErrors": [],
"provisionedPlans": []
}
My access token is
eyJ0eXAiOiJKV1QiLCJub25jZSI6IkFRQUJBQUFBQUFEWDhHQ2k2SnM2U0s4MlRzRDJQYjdySGc5dDJ4SmxkODFMRURNY1FuN3pMYVgyektLaDR2SF9FSFltd1JaQ3Y5TU55VDJOR250VmlDQVFmTXpiTWxoYkZWQ19nSEdtaWhfWlJfcVlpaGRyMHlBQSIsImFsZyI6IlJTMjU2IiwieDV0IjoiaUJqTDFSY3F6aGl5NGZweEl4ZFpxb2hNMllrIiwia2lkIjoiaUJqTDFSY3F6aGl5NGZweEl4ZFpxb2hNMllrIn0.eyJhdWQiOiJodHRwczovL2dyYXBoLm1pY3Jvc29mdC5jb20vIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvM2FjMThiOGMtNjY4ZC00NzBhLWJhMDctYWU0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idGlkIjoiM2FjMThiOGMtNjY4ZC00NzBhLWJhMDctYWU0MjdlMTkwZGEyIiwidW5pcXVlX25hbWUiOiJrb21hbC5oZW5kcmVAcmF5a29yLmNvbSIsInV0aSI6IkxtTnJoX1FZbUVHbUtSY1JHcWtGQUEiLCJ2ZXIiOiIxLjAifQ.JtXMDO2Whs24ItQIIPBEZj93Go5z0QowyZCy-msAw7-heGu7yQZrppuvBfv-rrAS1bvFw_aBDBALzX7rlHwsiU9KaEzrRdzUgc9lciDhuGsPZddGEZrSpTuhBPvLa-xI8_1bLMhSChLECU63rMnBYHZJesenWqPL0w1DsmkUHeR01Ff7l8pgsH3jemRK2NAr4LD-wyQrumJxz2h45luO9dICqPOGjI9hwrjNpSDJnhienDkUsrcOA2ijnWglCJ3GRN9RfrJ93osCaO3WpUoTIy66NApYR__YDGzO4HsTk_MA9OSQCHcw5mOaOeRKZmRTDPIokyYpeNgXBK9FmZivBg
Can't figure out that it is a access problem or provisioning problem. Can anyone suggest what's going wrong here.
In my MySQL database, I have a table named Messages which is having 4 rows , with unique message ID as 1,2,3,4.
When using REST Api I am accessing collection resource:
http://localhost:8080/messenger/webapi/messages
I am getting all the message entries as JSON , which is expected;
Please find below :
[
{
"author": "Vineet",
"creation": "09/12/2017",
"id": 1,
"message": "Message1"
},
{
"author": "Puneet",
"creation": "09/12/2017",
"id": 2,
"message": "Message2"
},
{
"author": "Dad",
"creation": "09/12/2017",
"id": 3,
"message": "Message3"
},
{
"author": "Mom",
"creation": "09/12/2017",
"id": 4,
"message": "Message4"
}
]
When using REST Api I am accessing the individual resource:
http://localhost:8080/messenger/webapi/messages/1 or
http://localhost:8080/messenger/webapi/messages/2 or
http://localhost:8080/messenger/webapi/messages/3 or
http://localhost:8080/messenger/webapi/messages/4
I am getting the expected response for every single resource e.g. for 1
{
"author": "Vineet",
"creation": "09/12/2017",
"id": 1,
"message": "Message1"
}
Problem : When I am trying to access url :
http://localhost:8080/messenger/webapi/messages/9 , where 9 is a resource that never exists in database.
I am getting a blank page or the last loaded page. and The HTTP Code coming is : 204.
When "9" id is not present , why is not there 404 message ?
Why 204 ?
The route is correct and only the paramerter which you have provided is wrong so there is no way you will get a 404 which is page not found but the request has hit service so it a successful service hit
I hope you can handle the error in exception handling.