I'm publishing the following MQTT request to the topic /v2/feeds/XXX.json, where XXX is the name of my feed.
{
"version": "1.0.0",
"datastreams": [
{
"id": "test",
"current_value": 25,
"unit": "Celsius",
"unit_symbol": "°C"
}
]
}
When I look at the develop page on the Xively website, I see a new channel called test has been created with the value 25, but it has no associated units.
How can I set the units for a datastream using MQTT?
The proper json request is:
{
"version": "1.0.0",
"datastreams": [
{
"id": "test",
"current_value": 25,
"unit": {
"symbol": "°C",
"label": "Celsius"
}
}
]
}
Related
As a marketer, I'm going through the EmailOctopus (email service provider) API docs (https://emailoctopus.com/api-documentation) and have trouble combining multiple requests in one.
Goal: Get all campaign reports for all campaigns exported to a CSV.
Step 1: Get all campaign IDs. This works.
curl GET https://emailoctopus.com/api/1.5/campaigns?api_key={APIKEY}
Step 2: Get the report for a single campaign. This works too.
curl GET https://emailoctopus.com/api/1.5/campaigns/{CAMPAIGNID}/reports/summary?api_key={APIKEY}
Step 3: Combine step 1 and 2 and export to a CSV. No idea how to proceed here.
Output step 1:
{
"data": [
{
"id": "00000000-0000-0000-0000-000000000000",
"status": "SENT",
"name": "Foo",
"subject": "Bar",
"to": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
],
"from": {
"name": "John Doe",
"email_address": "john.doe#gmail.com"
},
"content": {
"html": "<html>Foo Bar<html>",
"plain_text": "Foo Bar"
},
"created_at": "2019-10-30T13:46:46+00:00",
"sent_at": "2019-10-31T13:46:46+00:00"
},
{
"id": "00000000-0000-0000-0000-000000000003",
"status": "SENT",
"name": "Bar",
"subject": "Foo",
"to": [
"00000000-0000-0000-0000-000000000004",
"00000000-0000-0000-0000-000000000005"
],
"from": {
"name": "Jane Doe",
"email_address": "jane.doe#gmail.com"
},
"content": {
"html": "<html>Bar Foo<html>",
"plain_text": "Bar Foo"
},
"created_at": "2019-11-01T13:46:46+00:00",
"sent_at": "2019-11-02T13:46:46+00:00"
}
],
"paging": {
"next": null,
"previous": null
}
}
Output step 2:
{
"id": "00000000-0000-0000-0000-000000000000",
"sent": 200,
"bounced": {
"soft": 10,
"hard": 5
},
"opened": {
"total": 110,
"unique": 85
},
"clicked": {
"total": 70,
"unique": 65
},
"complained": 50,
"unsubscribed": 25
}
How can I get all campaign reports in one go and exported to a CSV?
May be this URLs be helpful
Merging two json in PHP
How to export to csv file a PHP Array with a button?
https://www.kodingmadesimple.com/2016/12/convert-json-to-csv-php.html
I am trying to fetch Pages from Sharepoint sites using graph API.
But when we make GET request with
https://graph.microsoft.com/beta/sites/{site-id}/pages/{page-id}
the response consists of webParts which only have type and data.
Inside data we have an id(which same as type) and an instanceId that is unique for every webPart.
Sample webPart:
{
"type": "d1d91016-032f-456d-98a4-721247c305e8",
"data": {
"id": "d1d91016-032f-456d-98a4-721247c305e8",
"instanceId": "c54a74ef-86c1-44aa-9ba4-802e6841e3a7"
}
My goal is to fetch webPages with complete details and then backup them to a local drive in any format.
The documentation of graph API shows that the responce would consist of complete details for the webPart, but it is not so.
Documentation link: https://learn.microsoft.com/en-us/graph/api/sitepage-get?view=graph-rest-beta&tabs=http
Sample request URL:
https://graph.microsoft.com/beta/sites/m365x214355.sharepoint.com,c1e5444e-12d8-43d3-96b1-f2f66559ef58,b181bdf0-9680-4988-81f7-a24aee4afd6a/pages
Webpart repsonse:
"webParts": [
{
"type": "rte",
"data": {
"innerHTML": "<p>Take a look at the team behind delivering amazing fashion events for Contoso.</p><p>Find out how the team uses the latest technology to plan amazing fashion shows and gather customer feedback for future events.</p><p>Meet the people behind Contoso's events, learn how to plan your own event, and find the necessary resources to run highly successful fashion shows, premiers, and extravaganzas!</p>"
}
},
{
"type": "d1d91016-032f-456d-98a4-721247c305e8",
"data": {
"id": "d1d91016-032f-456d-98a4-721247c305e8",
"instanceId": "c54a74ef-86c1-44aa-9ba4-802e6841e3a7"
}
},
{
"type": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d",
"data": {
"id": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d",
"instanceId": "75ccfeba-ad6c-416d-a859-4a6b114e156e"
}
},
{
"type": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d",
"data": {
"id": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d",
"instanceId": "f04e02fb-45e6-4e74-9f46-0c8d90e7fb8d"
}
},
{
"type": "275c0095-a77e-4f6d-a2a0-6a7626911518",
"data": {
"id": "275c0095-a77e-4f6d-a2a0-6a7626911518",
"instanceId": "c1a222b0-624e-4e30-b544-d2a67e8e1112"
}
}
Expected Response format:
"webParts": [
{
"type": "rte",
"data": {
"innerHTML": "<p>Here are the team's upcoming events:</p>"
}
},
{
"type": "d1d91016-032f-456d-98a4-721247c305e8",
"data": {
"title": "Events",
"description": "Display upcoming events",
"serverProcessedContent": {
"htmlStrings": {},
"searchablePlainTexts": {
"title": ""
},
"imageSources": {},
"links": {
"baseUrl": "https://www.contoso.com/sites/Engineering"
},
"componentDependencies": {
"layoutComponentId": "8ac0c53c-e8d0-4e3e-87d0-7449eb0d4027"
}
},
"dataVersion": "1.0",
"properties": {
"selectedListId": "032e08ab-89b0-4d8f-bc10-73094233615c",
"selectedCategory": "",
"dateRangeOption": 0,
"startDate": "",
"endDate": "",
"isOnSeeAllPage": false,
"layoutId": "FilmStrip",
"dataProviderId": "Event",
"webId": "0764c419-1ecc-4126-ba32-0c25ae0fffe8",
"siteId": "6b4ffc7a-cfc2-4a76-903a-1cc3686dee23"
}
}
}
]
I want webParts in the format as per documentation.
If the instanceId is unique then there might be some reference table to match these instanceIds and fetch the detailed webParts structure.
OneDrive user A shares a folder with OneDrive user B, and B can access that folder by using the share id.
For example using the graph explorer
GET https://graph.microsoft.com/v1.0/shares/{shareId}
yields
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#shares/$entity",
"id": "{shareId}",
"name": "ASharedFolder",
"owner": { ... }
}
Now, B wants to upload a new file to ASharedFolder.
Reading the OneDrive docs for upload I have tried
PUT https://graph.microsoft.com/v1.0/shares/{shareId}/driveItem/children:/SomeFile.txt:/content
Content-Type text/plain
some text goes here
as well as
PUT https://graph.microsoft.com/v1.0/shares/{shareId}/items/{sharedItemId}:/SomeFile.txt:/content
Content-Type text/plain
some text goes here
but both yield "BadRequest", "Unsupported segment type..."
Edit: I have now played out this scenario in the OneDrive Web UI using two different browsers for OneDrive users A and B, so I know that it is possible (without first adding the shared folder to B's own root), but I need some help figuring out the right request for the OneDrive REST API.
Does anyone know?
I checked the possibility of uploading files to a shared folder on OneDrive belonging to another user. I did not have any problems to achieve it using GraphExplorer.
Here is what I did:
I got a list of shared files and folders:
GET /me/drive/sharedWithMe
Returned (some of the data has been omitted):
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)",
"value": [
{
"#odata.type": "#microsoft.graph.driveItem",
"id": "<itemId>",
"name": "Folder name",
"parentReference": {
"driveId": "<myUserId>",
"driveType": "personal"
},
"remoteItem": {
"id": "<remoteItemId>",
"name": "Folder name",
"createdBy":
"user": {
"displayName": "Other user name",
"id": "<otherUserId>"
}
},
"folder": {
"childCount": 0
},
"parentReference": {
"driveId": "<otherUserId>",
"driveType": "personal"
},
"shared": {
"owner": {
"user": {
"displayName": "Other user name",
"id": "<otherUserId>"
}
}
}
}
}
]
}
Then I preformed PUT request with the following data:
PUT /drives/{otherUserId}/items/{remoteItemId}:/test.txt:/content
Content-Type: text/plain
The contents of the file goes here.
Response: Success - Status Code 201
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives('<otherUserId>')/items/$entity",
"id": "<itemId>",
"name": "test.txt",
"size": 35,
"createdBy": {
"application": {
"displayName": "Graph explorer"
},
"user": {
"displayName": "My user name",
"id": "<myUserId>"
}
},
"parentReference": {
"driveId": "<otherUserId>",
"driveType": "personal",
"id": "<parentReferenceId>",
"name": "Folder name",
"path": "/drives/<otherUserId>/items/<parentReferenceId>"
},
"file": {
"mimeType": "text/plain"
}
}
Then, on the subsequent GET /me/drive/sharedWithMe request, the value of the childCount of the folder has been increased to 1.
NOTE:
The \shares endpoint only allows GET requests to access a shared DriveItem or a collection of shared items. It does not allow to create new items.
We've recently seen what we believe is a change of functionality regarding the use of the top and skip query parameters when making a /drives call.
An example call is:
https://graph.microsoft.com/v1.0/sites/{siteid}/drives?top=1&skip=2
This results in the error message:
{
"error": {
"code": "invalidRequest",
"message": "$skip is not supported on this API. Only URLs returned by the API can be used to page.",
"innerError": {
"request-id": "14be8885-c3ba-48cc-862b-169dc2c02792",
"date": "2017-08-22T21:15:44"
}
}
}
We are trying to get a list of document libraries for a site collection. We would like to be able to page through them. Is this not the correct approach?
I understand that the concept of skipToken exists but do not receive one when limiting this call with the top query param.
https://graph.microsoft.com/v1.0/sites/muskpartners.sharepoint.com,d0e2f49b-e44c-43a6-8011-c00515666077,05e55f15-4584-4e3d-bf5c-dd4164b76685/drives
returns 3 items:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",
"value": [
{
"createdBy": {
"user": {
"displayName": "System Account"
}
},
"createdDateTime": "2017-07-25T05:42:33Z",
"description": "This library contains administrator-approved form templates that were activated to this site collection.",
"id": "b!m_Ti0EzkpkOAEcAFFWZgdxVf5QWERT1Ov1zdQWS3ZoWizkgpZiHkQpkllC4-bnhA",
"lastModifiedDateTime": "2017-07-25T05:42:33Z",
"name": "Form Templates",
"webUrl": "https://muskpartners.sharepoint.com/portals/Community/FormServerTemplates",
"driveType": "documentLibrary",
"quota": {
"deleted": 0,
"remaining": 0,
"total": 0,
"used": 0
}
},
{
"createdBy": {
"user": {
"displayName": "System Account"
}
},
"createdDateTime": "2017-07-25T05:41:53Z",
"description": "This system library was created by the PointPublishing feature to store stories that are used throughout the site collection.",
"id": "b!m_Ti0EzkpkOAEcAFFWZgdxVf5QWERT1Ov1zdQWS3ZoVz8ZvkSRbdTYvi75sQq3Tt",
"lastModifiedDateTime": "2017-07-25T05:41:53Z",
"name": "Pages",
"webUrl": "https://muskpartners.sharepoint.com/portals/Community/pPg",
"driveType": "documentLibrary",
"quota": {
"deleted": 0,
"remaining": 0,
"total": 0,
"used": 0
}
},
{
"createdBy": {
"user": {
"displayName": "System Account"
}
},
"createdDateTime": "2017-07-25T05:41:59Z",
"description": "This system library was created by the PointPublishing feature to store settings that are used throughout the site collection.",
"id": "b!m_Ti0EzkpkOAEcAFFWZgdxVf5QWERT1Ov1zdQWS3ZoU_AWZq16MrSLjg0Cv0MA8_",
"lastModifiedDateTime": "2017-07-25T05:41:59Z",
"name": "Settings",
"webUrl": "https://muskpartners.sharepoint.com/portals/Community/pSet",
"driveType": "documentLibrary",
"quota": {
"deleted": 0,
"remaining": 0,
"total": 0,
"used": 0
}
},
{
"createdBy": {
"user": {
"displayName": "System Account"
}
},
"createdDateTime": "2017-07-25T05:41:43Z",
"description": "Use the style library to store style sheets, such as CSS or XSL files. The style sheets in this gallery can be used by this site or any of its subsites.",
"id": "b!m_Ti0EzkpkOAEcAFFWZgdxVf5QWERT1Ov1zdQWS3ZoUmZuKEP6ZjQ75eVvVinqIN",
"lastModifiedDateTime": "2017-07-25T05:41:47Z",
"name": "Style Library",
"webUrl": "https://muskpartners.sharepoint.com/portals/Community/Style%20Library",
"driveType": "documentLibrary",
"quota": {
"deleted": 0,
"remaining": 0,
"total": 0,
"used": 0
}
}
]
}
When I use the top query param such as:
https://graph.microsoft.com/v1.0/sites/muskpartners.sharepoint.com,d0e2f49b-e44c-43a6-8011-c00515666077,05e55f15-4584-4e3d-bf5c-dd4164b76685/drives?top=1
I receive only one result and no way to page to the others.
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",
"value": [
{
"createdBy": {
"user": {
"displayName": "System Account"
}
},
"createdDateTime": "2017-07-25T05:42:33Z",
"description": "This library contains administrator-approved form templates that were activated to this site collection.",
"id": "b!m_Ti0EzkpkOAEcAFFWZgdxVf5QWERT1Ov1zdQWS3ZoWizkgpZiHkQpkllC4-bnhA",
"lastModifiedDateTime": "2017-07-25T05:42:33Z",
"name": "Form Templates",
"webUrl": "https://muskpartners.sharepoint.com/portals/Community/FormServerTemplates",
"driveType": "documentLibrary",
"quota": {
"deleted": 0,
"remaining": 0,
"total": 0,
"used": 0
}
}
]
}
If the skipToken is what I should be looking for, is it a bug that it is not returned in this case?
Not all ODATA parameters are supported by all endpoints, the /drives endpoint for example doesn't support the $skip parameter. What you're looking for instead is the $skipToken.
The $top parameter sets the page size. If you're call to the API has additional results (i.e. more drives in this case) then the results will include a skipToken value. Passing that token into the API will fetch the next page of results (and another skipToken if there are yest more data).
https://graph.microsoft.com/v1.0/sites/{siteId}/drives?$top=1&$skiptoken={skipToken}
You can read about using this parameter under Paging Microsoft Graph data in your app.
i am trying to fetch a json data in my rails app from a url. how to make this api call.
{
"name": "MagicList",
"count": 20,
"frequency": "realtime",
"version": 5,
"newdata": true,
"lastrunstatus": "success",
"lastsuccess": "Sat Apr 26 2014 14:34:40 GMT+0000 (UTC)",
"results": {
"collection1": [
{
"Title": {
"href": "http://www.magicbricks.com/propertyDetails/2-BHK-746-Sq-ft-Multistorey-Apartment-FOR-Sale-Sector-79-in-Gurgaon&id=C0gt4k2Fa9tzpSvf+uAgZw==",
"text": "2 BHK Multistorey Apartment in Sector-79"
},
"Price": "37.99 Lac(s)",
"Rate": "5,092",
"Size": "746 Sq-ft",
"Project Name": "",
"New_Resale": "New Property"
},
{
"Title": {
"href": "http://www.magicbricks.com/propertyDetails/2-BHK-1050-Sq-ft-Multistorey-Apartment-FOR-Sale-Sector-68-in-Gurgaon&id=M5jckQCuJaBzpSvf+uAgZw==",
"text": "2 BHK Multistorey Apartment in Sector-68"
},
"Price": "57.50 Lac(s)",
"Rate": "5,476",
"Size": "1050 Sq-ft",
"Project Name": "Project: Pareena Sec68",
"New_Resale": "New Property"
},
{
"Title": {
"href": "http://www.magicbricks.com/propertyDetails/3-BHK-1875-Sq-ft-Multistorey-Apartment-FOR-Sale-Sector-37C-in-Gurgaon&id=gw8zjmcA/b1zpSvf+uAgZw==",
"text": "3 BHK Multistorey Apartment in Sector-37C"
},
"Price": "60.0 Lac(s)\nOnwards",
"Rate": "3,200",
"Size": "1875 Sq-ft",
"Project Name": "Project: Spire Greens",
"New_Resale": "Resale"
}
}
}
dont know how it can be achieved, which gem should be used.
Using 'open-uri'
url = "http://..."
data = JSON.parse(open(url).read)
Or using 'net'
require "net/http"
url = "http://..."
resp = Net::HTTP.get_response(URI.parse(url))
data = JSON.parse(resp.body)
This is not an answer to your question, but stack overflow won't let me post a comment without 50 reputation.
You may want to edit your API key out of your question, since it's the equivalent of your password for using their API services.
Yes you can easily use builtin stuff:
uri = "https://yourapithinkg.com/list?api_key=#{ENV.fetch('API_KEY')}"
result = JSON.parse(Net::HTTP.get(URI.parse(uri)))
Most people like to load in other libraries but its not really worth it.