Setting HTML as supported messageformat in UCWA - ucwa

I have a functional ucwa client that only works with plain messages. According to the lync documentation, a PUT request is needed to change the supported modality and message format, and that an If-Match header is required to verify the request is not for an out-of-date status.
For example, a GET request to /ucwa/oauth/v1/applications/102628975647/communication will return
{
"9b5c7fdf-2c5f-462e-a4e3-39663f09301a": "please pass this in a PUT request",
"supportedModalities": [],
"supportedMessageFormats": [
"Plain"
],
"_links": {..},/*ommitted for brevity */
"rel": "communication",
"etag": "3010254294"
}
I PUT back this, with an If-Match: 3010254294 header:
{
"9b5c7fdf-2c5f-462e-a4e3-39663f09301a": "please pass this in a PUT request",
"supportedModalities": [],
"supportedMessageFormats": [
"Plain", "Html"
],
"rel": "communication",
"etag": "3010254294"
}
But I consistently get a 428 PreconditionRequired error, which, according to documentation, means that I am missing the If-Match header. Various combinations of ETag and If-Match also fail. What is the proper format for this request?

I remember running into this issue when I was trying to figure out why I could not receive HTML-formatted messages. The issue being that you appear to have the data correct except the If-Match header is very particular in that it would only work for me when I had the value quoted and it may/may not work for single quotes.
If-Match: "3010254294"
Relevant Fiddler Trace: UCWA Html Messaging.saz

Related

A 400 error occurs when creating a OneDrive API upload session

Create an upload session to upload large files to oneDrive.
Below is the request address.
https://graph.microsoft.com/beta/users/{userId}/drive/root:/UploadFiles/{fileName}:/createUploadSession
Request Body
{
"item": {
"#odata.type": "microsoft.graph.driveItemUploadableProperties",
"#microsoft.graph.conflictBehavior": "rename",
"name": "largefile.dat"
}
}
An Invalid request error occurs. What's wrong with it? I watched the tutorial and tested it.
POST /drive/root:/{item-path}:/createUploadSession
Content-Type: application/json
{
"item": {
"#odata.type": "microsoft.graph.driveItemUploadableProperties",
"#microsoft.graph.conflictBehavior": "rename",
"name": "largefile.dat"
}
}
https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-beta#create-an-upload-session
As Shiva suggested in a comment on the question, the issue is that the value of #odata.type is not correct for this case. In general you should not provide it at all as the schema is strongly typed and therefore the appropriate value can be derived without any client-driven hints.

How to reference a resource in a update-request of a hypermedia api?

I did some research about how REST APIs work and how to link resources via hypermedia. Most of the examples about linking resources is related to the response of the server. But I wonder how to reference to other resources when a certain resource should be updated.
Let´s take the simple resource of a person living at a specific location:
/api/persons/alice
{
"name": "Alice",
"location": {
"id": 1,
"links": {
"self": "/api/locations/1"
}
}
}
Now I want to update the location to another existing location. But how do I represent that?
Would I:
refer to the id of the new location
PUT /api/persons/alice
{
"name": "Alice",
"location": 2
}
refer to the URI of the new location
PUT /api/persons/alice
{
"name": "Alice",
"location": "/api/locations/2"
}
anything else?
HTTP PUT has remote authoring semantics - you should think of the payload as being the new representation of a document, being manipulated by some general purpose HTTP aware document editor.
GET /api/persons/alice HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/json
{
"name": "Alice",
"location": {
"id": 1,
"links": {
"self": "/api/locations/1"
}
}
}
PUT /api/persons/alice HTTP/1.1
Content-Type: application/json
{
"name": "Alice",
"location": {
"id": 2,
"links": {
"self": "/api/locations/2"
}
}
}
200 OK
The assumption here is that the consumer of your API is familiar with the schema here, and understands the semantics, which fields are optional, which are required, and so on.
(Getting this to work on a long time scale means investing effort in designing your schema well, choosing reasonable defaults, and so on).
Please observe this part of the PUT specification with care:
An origin server SHOULD verify that the PUT representation is consistent with any constraints the server has for the target resource that cannot or will not be changed by the PUT.... When a PUT representation is inconsistent with the target resource, the origin server SHOULD either make them consistent, by transforming the representation or changing the resource configuration...
...
An origin server MUST NOT send a validator header field (Section 7.2), such as an ETag or Last-Modified field, in a successful response to PUT unless the request's representation data was saved without any transformation applied to the body....
In other words, the server doesn't need to "store" the new representation as provided.

Zabbix API Error when Calling from Cherwell

I am looking at getting Cherwell talking to Zabbix but stumbling at what I understand is the easiest starting point. I have a user setup in Cherwell as part of the webservice which I have confirmed I can log into Zabbix with.
As part of the web call I am performing the basic Zabbix version check.
{
"jsonrpc": "2.0",
"method": "apiinfo.version",
"params": {},
"id": 1
}
I am getting a -32600 error, Invalid Request, data: the received JSON is not a valid JSON-RPC request.
From what I have read you should be able to do this even if you are not authenticated.
I am though getting back a result code of 200 which means the connection is solid but just not returning what I am expecting.
Thanks
That error usually means the double quotes are missing, missplaced, or escaped in a wrong way. The code by itself is fine.
#API_URL=https://.../zabbix/api_jsonrpc.php
#CONTENT_TYPE=Content-Type: application/json-rpc
{
"jsonrpc": "2.0",
"method": "apiinfo.version",
"id": 1,
"params": {}
}

Try to patch TEXT in a Classroom announcements over API

I'm not able to change 'text' in an announcements using Google-Classroom API.
When I try to use the PATCH method I have the following error:
{
"error": {
"code": 400,
"message": "updateMask: Non-supported update mask fields specified",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "updateMask",
"description": "Non-supported update mask fields specified"
}
]
}
]
}
}
request and updateMask
I send a updateMask 'text' and a text in request body.
When I try with the updateMask 'state,scheduledTime' I get a successful.
Has anyone ever had this error?
References:
https://developers.google.com/classroom/reference/rest/v1/courses.announcements/patch
I had the same issue. Despite what the documentation seems to indicate (that updateMask can be text), I couldn't get it to work.
I got around it by creating a new post with the information from the announcement, and deleting the old announcement.
This is probably what you did too.

How to post event with metadata to stream through HTTP API

I'm using EventStore and want to post a message (event) to it. I use the HTTP API for testing purposes. I've managed to post the event itself, with an event type specified, but I can't figure out how to specify metadata for my event. (and I must provide this metadata because my consuming application on the other side expects it).
This is what my HTTP request looks like:
Content-Type: application/json
ES-EventType: My.own.event.type
POST http://10.0.75.2:2113/web/index.html#/streams/foobar
{
"props": "andvalues"
}
Do I specify metadata in the body in through headers? I can't find much docs about this, only the official that doesn't mention it.
The documentation mentions the full schema for an event being written. It looks like this:
[
{
"eventId" : "string",
"eventType" : "string",
"data" : "object",
"metadata" : "object"
}
]
For example:
[
{
"eventId": "fbf4a1a1-b4a3-4dfe-a01f-ec52c34e16e4",
"eventType": "event-type",
"data": { "a": "1" },
"metadata": { "b": "2" }
}
]
Note that it's an array, and that you must pass content-type as application/vnd.eventstore.events+json
Check this page, scroll to Event Store Events Media Type.