Microsoft Graph REST API to UPDATE Microsoft Planner Tasks? - microsoft-graph-api

I think this might be a simple quote escape issue, but can’t figure it out.
I am trying to update a microsoft planner task using CURL with REST API. I can CREATE tasks (from a custom application called FileMaker to Microsoft Planner using Microsoft Graph API) without issue, but when I try to UPDATE a planner task, I get an error that "The If-Match header must be specified for this kind of request." But I am including the If-Match header, just might not be entering it correctly.
The URL is:
"https://graph.microsoft.com/v1.0/planner/tasks/" & $microsoftplannerTaskID
The CURLOPTIONS, I am entering within FileMaker is ...
"-X PATCH " &
" -H "Authorization: Bearer " & $$userToken & """ &
" -H "Content-Type: application/json"" &
" -H "If-Match: " & $microsoftPlannerTasketag & """ &
" -d #$PlannerTaskDetails"
ENDS UP LOOKING LIKE THIS …
-X PATCH -H "Authorization: Bearer wEXu<>k_QQY" -H "Content-Type: application/json" -H "If-Match: W/"JzEtVGFzayAgQEBAQEBAQBAQEBARCc="" -d #$PlannerTaskDetails
When I CREATE the task initially, the response show …
"#odata.etag":"W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=""
Which I am using in the cURL header above. BUT … I am stripping the W/ and the quotes. The W/ means it is a “weak”, and I assume we don’t include that in the PATCH header, but I did try adding it anyway with no success.
Here is Microsoft’s UPDATE PLANNERTASK reference …
https://learn.microsoft.com/en-us/graph/api/plannertask-update?view=graph-rest-1.0&tabs=http
I can update tasks using POSTMAN without issue, but I dont know what their header looks like when it sends the request.
I can get it to work in Postman and in there I have entered for the Plan ETag variable this …
W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="
I notice in postman the header shows etag is
W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="
And the body returns as
"#odata.etag": "W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="",
It’s got to be a simple syntax issue with my curloption variable, but I can’t figure it out.
I also tried removing the W/ in the If-Match header, so it looks like this:
-H "If-Match: "JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=""
And the extra quotes in the If-Match header, so it looks like this:
-H "If-Match: JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="
All of these result in the same “if-match” error.
One interesting thing …if I change the If-Match to include a slash in front of the quotes
-H "If-Match: "JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=""
I get an error 10 “requested data is missing” in Filemaker’s script debugger and no response from the insert from url statement. Makes sense though, since it is reading this as “if-match: ”
And same thing if I add the W/ back in
-H "If-Match: W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=""
Gives me error 10 as well
If you have any thoughts, I would greatly appreciate your help!!

Try this:
"-X PATCH " &
"-H " & quote("Authorization: Bearer " & $$userToken) &
"-H " & quote("Content-Type: application/json") &
"-H " & quote("If-Match: W/" & quote($microsoftPlannerTasketag)) &
"-d #$PlannerTaskDetails"

Related

Ratpack/Groovy - read the body of a call

I want to create a "mock" server using Ratpack/Groovy and we need to read the data-raw from a call
I haven't had a problem reading headers or parameters, but I need to read the body of a request
Examplle:
curl --location --POST request 'http://localhost:5050/authenticate' \
--header 'Content-type: application/json' \
--raw-data '{
"username": "testbase01#domain.com",
"password": "12345678"
}'
we need to parse and process the username and password fields
We have tried to read the request.body, or the body.text, but we have not been successful.
Basically the example found in the solution at https://stackoverflow.com/questions/23636248/parse-json-in-ratpack-groovy would be what we need, but it hasn't worked for us either
Our environment has the following dependencies
#Grab('io.ratpack:ratpack-groovy:1.6.1'),
#Grab('org.slf4j:slf4j-simple:1.7.22'),
#Grab("io.ratpack:ratpack-jackson:0.9.17")
and we are using https://github.com/Vad1mo/hello-world-rest as primary image
If you have a small example, to be able to adapt it to our needs

Postman-generated cUrl and Swift codes result in status 415, but when running the same from postman itself I get 400 (which is correct)

I need to post a single key-value pair from a Swift iOS app using form-data.
The Postman example that was provided by the back-end developer works:
The Postman Body tab shows "SelectedCreditCard" under "KEY" and "34" under "VALUE"
The method is POST.
The Postman Headers tab shows "Content-Type" under KEY and "application/x-www-form-urlencoded" under VALUE, and an additional authorization token header.
When running from Postman I get status 400 with a JSON body that contains an "Invalid credit card" warning. This is the expected result.
When implementing this in Swift I received 415 (media not supported). I pasted the curl code generated by Postman to the Mac command line, just to see how it looks, and to my surprise I got the same result as in the iOS App.
The curl code:
curl --location --request POST 'https://stg.xxx.com/api/xxx/SavePaymentInfo' \
--header 'Authorization: Bearer xxxxxxxxxx' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--form 'SelectedCreditCard=34'
The curl result:
{"$type":"Microsoft.AspNetCore.Mvc.ProblemDetails,
Microsoft.AspNetCore.Mvc.Core",
"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13",
"title":"Unsupported Media Type",
"status":415,
"traceId":"0HLTFOL7EGBUA:00000007"}%
I have also tried the generated Objective C code provided by Postman and the generated Swift code, and in all cases the result is 415. The only case in which I get the correct result (400 with an invalid card warning) is when running the post directly from Postman itself. I wonder what causes this gap.
Found the solution: in curl, instead of "Content-Type", the header name should be "Accept" (no need to specify a Content-Type)

Is Avro Schema Registry compatibility lost when using arrays?

I'm using Confluent Avro Schema Registry with backward compatibility option. I upload this schema which is a record inside an array (the [ ]-brackets). This record only contains one string field.
curl -X POST -i -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": "[{\"type\": \"record\", \"name\": \"TestRecord\", \"namespace\": \"com.company\", \"fields\": [{\"name\": \"testname\", \"type\": \"string\"}]}]"}' http://localhost:8081/subjects/test99-value/versions
Everything goes well and I get a success response back (200).
Now I want to sanity check this so I remove the string field and I add a integer field. This should definitely not be compatible, neither forward nor backwards.
curl -X POST -i -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": "[{\"type\": \"record\", \"name\": \"TestRecord\", \"namespace\": \"com.company\", \"fields\": [{\"name\": \"testname2\", \"type\": \"int\"}]}]"}' http://localhost:8081/subjects/test99-value/versions
The problem is that this also returns a success even though this cannot possibly be correct. Am I missing something very basic here?
If I do this with a record that isn't inside an array I get the expected error from the schema registry.

Is this Calendly.com URL Valid?

I am using webhooks for the first time with calendly.com. I would like to create a subscription as described here. When I get to doing this
curl --header "X-TOKEN: <your_token>" --data "url=https://blah.foo/bar&events[]=invitee.created" https://calendly.com/api/v1/hooks
I am concerned that the url is not in a valid format. I tried replacing the & with a ? as in here
curl --header "X-TOKEN: <your_token>" --data "url=https://blah.foo/bar?events[]=invitee.created" https://calendly.com/api/v1/hooks
but I receive this error
{"events":{"events":["can't be blank]}}
Likewise, I try to leave the & and everything after it blank and it give the same error as above.
But using a url with the & and everything in it gives a 404 not found error. Can a url even have the format they are saying is required?
But using a url with the & and everything in it gives a 404 not found error.
The URL part in the following is just the https://blah.foo/bar part before the & character.
curl --header "X-TOKEN: <your_token>" --data "url=https://blah.foo/bar&events[]=invitee.created" https://calendly.com/api/v1/hooks
The events[]=invitee.created part is a separate parameter and value. It’s not part of the url.
See the Create A Webhook Subscription page in the calendy docs:
So the URL is the site that runs your webhook; you don’t send the events parameter/value back to that site—instead you’re sending both the url param and events param to the calendly API endpoint at https://calendly.com/api/v1/hooks. The calendly backend presumably then calls to https://mywebsite.com/webhooks/invitee_created or https://blah.foo/bar whatever url you’ve given it—but without the events parameter, which is for calendly’s internal use.

Instagram API - cryptic response; not sure if working and unable to test omniauth with this

I am working on a Rails app that has as the requirement logging in with omniuth to Instagram. This would be my first time using Instagram's OAuth endpoint and it is unclear whether it is working (and not clear to project manager either).
I'm using their cURL implementation with the following (will reset it in future) but getting "No matching code found" error which would seem to be the logical first step.
curl \-F 'client_id=4658fa17d45244c88dd13c73949a57d7' \
-F 'client_secret=ae6cfe5d13544eada4dece2ec40ac5dc' \
-F 'grant_type=authorization_code' \
-F 'redirect_uri= http://seek-style.herokuapp.com/arc/services/instagram' \
-F 'code=CODE' \https://api.instagram.com/oauth/access_token
with response
{"code": 400, "error_type": "OAuthException", "error_message": "No matching code found."}
Is there something that I am doing obviously wrong? Is there a finished example of how to get this done? I have seen https://github.com/ropiku/omniauth-instagram but can't tell if still working. Spec's pass but the actual call is mocked.
Edit #1
Per comments, I have added a link to repo https://github.com/trestles/seek that is being used to deploy to Heroku. There's basically nothing in the app and the above cURL to the best of my knowledge should be working (and isn't) so I haven't really even tested this. Perhaps I'm misunderstanding even how Instagram's API is working.
So, I have done a little research on Instagram API.
All the required info is located here: http://instagram.com/developer/authentication/
First of all, you need to get one-time CODE from Instagram. For your app it is pretty easy.
Just set href for your 'auth to instagram' link to:
"https://api.instagram.com/oauth/authorize/?client_id=4658fa17d45244c88dd13c73949a57d7&redirect_uri=http://seek-style.herokuapp.com/arc/services/instagram&response_type=code"
You will receive a redirect from API with CODE as a parameter.
You can handle it in services_controller#instagram or simply extract from application logs.
There should be something like
Processing by ServicesController#instagram as HTML
Parameters: {"code"=>"c25dcdcb96ed4eb9a508fede0cb94e87", "state"=>"e3d6dc22d6cd3cdebf6fb9e51a728a120a6d901cc382c4bf"}
Then you should request an ACCESS_TOKEN from the API
using cURL:
curl \-F 'client_id=YOUR_CLIENT_ID' \
-F 'client_secret=YOUR_CLIENT_SECRET' \
-F 'grant_type=authorization_code' \
-F 'redirect_uri= http://seek-style.herokuapp.com/arc/services/instagram' \
-F 'code=CODE_FROM_ABOVE' \https://api.instagram.com/oauth/access_token
Or using RestClient in services_controller#instagram :
resp = RestClient.post 'https://api.instagram.com/oauth/access_token', {
client_id: 'YOUR_CLIENT_ID',
client_secret: 'YOUR_CLIENT_SECRET',
grant_type: 'authorization_code',
redirect_uri: 'http://seek-style.herokuapp.com/arc/services/instagram',
code: params[:code]
}
The cURL response or resp.body in controller should contain something like:
{
"access_token":"1515660384.9f652d3.fcb1e712d41347069ad5c65ccfada994",
"user":{
"username":"petro.softserve",
"bio":"",
"website":"",
"profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/anonymousUser.jpg",
"full_name":"",
"id":"1515660384"
}
}

Resources