I am new to programming with Rails API.
To test my Rails API, I need to build a manual POST request with data format like
{
"user":
{
"email": "abc#gmail.com",
"name": "abc",
}
}
I am trying to use Simple REST Client but not able to get the URL with data in the above format. How do I write the URL to get the data in the right format?
Related
I have a Rails API with minimal authentication - just a simple bearer token hooked up to Auth0.
I have one endpoint which looks like this:-
mysite.com/api/users/1/calendar.ics
The URL is unauthenticated, to allow people to subscribe to their calendars.
I'm basically trying to hide the id, and change it to a SecureRandom hex or something, so that other users can't just change the id and see other individuals' calendars.
How would I achieve this?
My front end would need some way of knowing what the encrypted string was - and since we only have bearer token auth, I'm not sure if it's secure enough to just pass the calendar URL into authenticated requests to users/1, for example:-
{
"id": 1,
"name": "John Smith",
"email": "email#email.com",
"intro": "string",
"calendar_url": "mysite.com/api/users/jUhGtDhajaluyt34/calendar.ics"
"created_at": "2021-05-13T16:15:09.748Z",
"updated_at": "2021-05-13T16:15:09.748Z"
}
Is delivery of the URL like this even a valid concern?
I call my mailbox using REST calls to MSGraph:
GET https://graph.microsoft.com/v1.0/me/mailfolders/inbox/messages
As expected I receive a Json with my mails.
To play with a specific mail (move, delete,forward, ...) I saw that the API should be called like
POST me/messages/{id}/forward
I can't target the message if I provide the value of the id field that I get from the JSon. Where to find the correct {id} that I should use?
my result is like the example at https://developer.microsoft.com/en-us/graph/graph-explorer see id: field when calling GET my mails.
Thanks
The id from JSON is OK. what you missing is you have not set the post conent for move/forward.
If you use the forward API, you should set the post content like below:
{
"Comment": "FYI",
"ToRecipients": [
{
"EmailAddress": {
"Address": "XXX#XXX.onmicrosoft.com"
}
}
]
}
This is the worked forward url for me(you can implement the move/delete like this too):
https://graph.microsoft.com/v1.0/me/messages/AAMkAGNjZTcyZDJmLTkzMjYtNGQwNi05Y2UxLTc5NDk0NjEwNjJjMABGAAAAAAAUYpVLVYiKTINMO3MZR0H5BwB3NF3PTyl5QIQd59edwRO9AAAAAAEMAAB3NF3PTyl5QIQd59edwRO9AAApBI9fAAA=/forward
For information please see:
https://learn.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-2.0/mail-rest-operations#ForwardDirectly
I am building a Rails 5 backend API which will receive requests from my Ember app. However I'm having some trouble getting Ember to format the request in a way my Rails server understands.
By default, Rails creates controllers to expect parameters in this format, assuming the model is a, say, Car:
"car": {
"id": "1",
"name": "Foo",
"bar": "Bar",
...
}
However it looks like Ember is sending requests in this format:
"data": [
{
id: "1",
type: "cars",
attributes: {
"name: "Foo",
"bar": "Bar",
...
}
]
What can I do to make Ember send request payloads in a way my Rails server will understand? Thank you.
Your Rails is accepting REST adapter format, for that to work properly, your adapter should extend DS.RESTAdapter and serializer should extend DS.RESTSerializer. By default it will comes with JSONAPIAdapter and JSONAPISerializer.
If you are having control over the back end code, then consider writing json-api format response for that ember will work out of the box.
Reference:
https://emberjs.com/api/ember-data/2.14/classes/DS.RESTAdapter
https://emberjs.com/api/ember-data/2.14/classes/DS.RESTSerializer
https://emberjs.com/api/ember-data/2.14/classes/DS.JSONAPIAdapter
https://emberjs.com/api/ember-data/2.14.9/classes/DS.JSONAPISerializer
I'm trying to use the create_flow endpoint to the Survey Monkey API. It is sending back a status 3 message with the following error:
additional properties not defined by 'properties' are not allowed in field '_data'
I'm able to do successfully use all other API endpoints and have a valid API key and durable OAuth token.
Here's an example JSON body that I'm sending to: https://api.surveymonkey.net/v2/batch/create_flow?api_key=apikeyhere
{
"survey": {
"template_id": "566",
"survey_title": "test1",
"collector": {
"type": "email",
"name": "collector1",
"recipients": [
{
"email": "email#example.com"
}
]
},
"email_message": {
"reply_email": "myemail#example.com",
"subject": "this is a test"
}
}
Note: JSON formatting here is being generated automatically using RJSONIO
Any ideas what might be causing the error? It seems like all fields are correctly named and where they're supposed to be, so I'm not sure what the problem is.
It's a bad error message unfortunately - it's a known issue. It means you are providing extra keys that are not part of the create_flow schema.
The issue here is that the "email_message" and "collector" keys have been nested inside of "survey", instead of being in the main JSON body like the "survey" key. Move them out a level and it should work.
I'm trying to figure out how to write a google places POST request using HTTParty. I was able to do a GET request but can't figure out how to work around the fact that Google Places has a nested parameter to post into. Here is the json syntax from the api documentation. Can someone help me translate this into the syntax that can work with HTTParty.post
POST https://maps.googleapis.com/maps/api/place/add/json?sensor=true_or_false&key=api_key HTTP/1.1
Host: maps.googleapis.com
{
"location": {
"lat": -33.8669710,
"lng": 151.1958750
},
"accuracy": 50,
"name": "Google Shoes!",
"types": ["shoe_store"],
"language": "en-AU"
}
The httparty gem includes an example that posts nested JSON to a server.