I am trying to create a iOS 12 Shortcut based on the Gautrain API.
I want to do a POST to the URL https://api.gautrain.co.za/transport-api/api/0/journey/create with the following payload:
{
"geometry": {
"coordinates": [
[
28.23794,
-25.74762
],
[
28.05693,
-26.10858
]
],
"type": "MultiPoint"
},
"profile": "ClosestToTime",
"maxItineraries": 3,
"timeType": "DepartAfter",
"only": {
"agencies": [
"edObkk6o-0WN3tNZBLqKPg"
]
}
}
I have entered all these details into a "Get Contents of URL" block. For the elements of the "coordinates" arrays I have used "Number".
The problem is that when I track what my phone is sending via mitmproxy, it sends all the information correctly, but the coordinates have been rounded to integers:
{
"geometry": {
"coordinates": [
[
28,
-25
],
[
28,
-26
]
],
"type": "MultiPoint"
},
"maxItineraries": 1,
"only": {
"agencies": [
"edObkk6o-0WN3tNZBLqKPg"
]
},
"profile": "ClosestToTime",
"timeType": "DepartAfter"
}
For this reason, the request is not giving the desired results.
I have a feeling this may be a bug, but is there something I am missing where I can tell Shortcuts to use the full set of digits?
I have found the problem. Since I am in South Africa, the numbers are expected to have commas instead of periods for decimals. I would have loved some feedback in the field that this wasn't a valid number instead of just silently ignoring the decimal.
The solution therefore was to change the "28.23794" in the entry box to "28,23794".
I might also link to postman-echo.com as an excellent tool for debugging these kinds of requests.
Related
Let's imagine I have a schema with 2 properties:
"properties": {
"name": {
"type": "string",
"minLength": 2,
"pattern": "<some unmatchable pattern>",
"x-constraints": "Capitalized(required = true)"
},
"petType": {
"type": "string",
"minLength": 2,
"pattern": "<some unmatchable pattern>",
"x-constraints": "Capitalized(required = true)"
}
}
What will happen if I send an invalid field? Is there any written in stone precedence of validation order? I.e. can a dependent service be sure it will always get the "Wrong length" error if name="a", even though other constraints don't match?
I tried official documentation but had no luck. Tests seem to return different error messages, but not sure if not due to the nature of test itself.
I am using the Fitbit endpoint in iOS app to fetch the steps as below:
https://api.fitbit.com/1/user/-/activities/steps/date/2019-07-01/1d/15min/time/12:00/12:15.json
This is to fetch the steps on a date for some time interval but it returns the array of some activities like Yoga, Walking, Winter activities etc. but not returning the steps count for the time interval. Can anyone please tell me how can I fetch the data for the same?
It returns the result as:
"categories": [
{
"activities": [
{
"accessLevel": "PUBLIC",
"activityLevels": [
{
"id": 3016,
"maxSpeedMPH": -1,
"mets": 8.5,
"minSpeedMPH": -1,
"name": "6 - 8 inch step"
},
{
"id": 3017,
"maxSpeedMPH": -1,
"mets": 10,
"minSpeedMPH": -1,
"name": "10 - 12 inch step"
}
],
"hasSpeed": false,
"id": 90004,
"name": "Aerobic step"
},
{
"accessLevel": "PUBLIC",
"hasSpeed": false,
"id": 3015,
"mets": 6.5,
"name": "Aerobic, general"
},
I found the reason behind Fitbit returning such data. It is just because the intraday data fetch requires the review from Fitbit or we can use the "personal" application type to get the data.
This query:
https://www.googleapis.com/youtube/v3/channelSections?part=snippet%2CcontentDetails%2Ctargeting&channelId=UC-9-kyTW8ZkZNDHQJ6FgpwQ&key={YOUR_API_KEY}
returns lots of data like this:
{
"kind": "youtube#channelSection",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/oIyqO89jk-vcfHm5Kuz3sikdUzc\"",
"id": "UC-9-kyTW8ZkZNDHQJ6FgpwQ.lc3PRFGaA4k",
"snippet": {
"type": "singlePlaylist",
"style": "horizontalRow",
"channelId": "UC-9-kyTW8ZkZNDHQJ6FgpwQ",
"position": 0
},
"contentDetails": {
"playlists": [
"PLFgquLnL59alW3xmYiWRaoz0oM3H17Lth"
]
},
"targeting": {
"regions": [
"US"
]
}
},
Is there any way to fetch only items with specific region?
Thanks for any help.
You can't filter these channel sections in your query like that. What you'd have to do is get the list of ChannelSections from that channel, store it in an object, and check if the targeted region for each channel section matches what you want (i.e. the value in targeting.regions[] equals XX, where XX is the region you're looking for). Then, you could store the channel sections that you wanted to find into an array and return that. If you're concerned about time, you'd have to set up a server that can do all of that for you.
I am getting JSON data from a webservice and try to store that in Core Data with Magical Record. I read the great post (and only documentation?) "Importing data made easy" by Saul Mora but I still do not really understand what I need to do to get all data in my entities.
Here is the JSON the web service returns:
{
"ApiVersion": 4,
"AvailableFileSystemLibraries": [
{
"Id": 10,
"Name": "Movie Shares",
"Version": "0.5.4.0"
},
{
"Id": 11,
"Name": "Picture Shares",
"Version": "0.5.4.0"
},
{
"Id": 5,
"Name": "Shares",
"Version": "0.5.4.0"
},
{
"Id": 9,
"Name": "Music Shares",
"Version": "0.5.4.0"
}
],
"AvailableMovieLibraries": [
{
"Id": 3,
"Name": "Moving Pictures",
"Version": "0.5.4.0"
},
{
"Id": 7,
"Name": "MyVideo",
"Version": "0.5.4.0"
}
],
"AvailableMusicLibraries": [
{
"Id": 4,
"Name": "MyMusic",
"Version": "0.5.4.0"
}
],
"AvailablePictureLibraries": [
{
"Id": 8,
"Name": "Picture Shares",
"Version": "0.5.4.0"
}
],
"AvailableTvShowLibraries": [
{
"Id": 6,
"Name": "MP-TVSeries",
"Version": "0.5.4.0"
}
],
"DefaultFileSystemLibrary": 5,
"DefaultMovieLibrary": 3,
"DefaultMusicLibrary": 4,
"DefaultPictureLibrary": 0,
"DefaultTvShowLibrary": 6,
"ServiceVersion": "0.5.4"
}
The entities I want to store that data in look like this:
There is also a Server entity with a 1:1 relationship to ServerInfo.
What I want to do:
Store basic data (ApiVersion, ...) in ServerInfo. This I already got to work.
Store each object in AvailableXYLibraries in BackendLibrary (1:n relationship from ServerInfo).
Set type based on the XY part of AvailableXYLibraries, for example "movie" for AvailableMovieLibraries.
Set defaultLibrary to true if this library is referenced by DefaultXYLibrary.
Set providerId to servername + LibraryId as there are multiple servers that can have BackendLibraries with the same numeric ID.
Is this possible with Magical Record? I guess I need to implement some of the import hooks and set some user info keys, but everything I read doesn't really tell me where to set what user info key or implement which method where and how.
I hope this made sense and that you can give me some hints :) Thanks!
The structure of this data is quite a bit different from your Core Data model. What you'll most likely have to do is iterate a bit on the dictionary. That is, there are various collections of library data, eg. FileSystemLibraries, AvailableMovieLibraries, etc. You'll have to get the array out of those keys, and then map your entities as I described in the article. In order to launch the process, you'll have to call
[BackendLibrary importFromArray:arrayFromDownloadedDictionary];
where the arrayFromDownloadedDictionary is each array in the example dictionary you've posted. Once you give the array to MagicalRecord, and provided the proper field mapping, MagicalRecord will then import and create all the entities for you at that point.
Make sure you map "Id" to BackendLibary.id, "Name" to BackendLibrary.name, and "Version" to BackendLibrary.version
Message parameter doesn't allow html, so tried to use message_tags parameter in this format, but with real values(format from here http://developers.facebook.com/blog/post/592/):
{
"19": [
{
"id": 101961456910,
"name": "Marmot",
"offset": 19,
"length": 6
}
],
"0": [
{
"id": 1207059,
"name": "Dhiren Patel",
"offset": 0,
"length": 12
}
]
}
and no result. Tried different values, there are no errors, but no result.
The message_tags parameter isn't one you can set via the API.
Did you find documentation suggesting otherwise? invalid parameters are for the most part silently ignored when you make a POST request