Error creating events with Microsoft graph - events

$p=array(
'subject'=>'Registrado desde iSchool',
'body'=>array(
'contentType'=>'HTML',
'content'=>'Evento de prueba',
),
'start'=>array(
'dateTime'=>'2017-05-28T12:00:00',
'timeZone'=>'Pacific Standard Time'
),
'end'=>array(
'dateTime'=>'2017-05-28T17:00:00',
'timeZone'=>'Pacific Standard Time'
),
'location'=>array('displayName'=>'Mi casa'),
'attendees'=>array(
'emailAddress'=>array('address'=>'email', 'name'=>'name'),
'type'=>'required'
),
);
$this->crear('calendars/'.$this->mg_model->idCalendarioUsuario().'/events', $p);
This function "$this->mg_model->idCalendarioUsuario()" Return the calendar ID
public function crear($objeto, $datos){
//$this->graph->setApiVersion("beta");
$r = $this->graph->createRequest("POST", "/me/$objeto")
//->addHeaders(array("Content-Type" => "application/json"))
->attachBody($datos)
->setReturnType(Event::class)
->execute();
}
Error: 400 Bad Request` response: { "error": { "code": "BadRequest", "message": "Property attendees in payload has a value that does not matc (truncated...)
What am I doing wrong?

The JSON payload for your example should look like this:
{
"subject": "Registrado desde iSchool",
"body": {
"contentType": "HTML",
"content": "Evento de prueba"
},
"start": {
"dateTime": "2017-05-28T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2017-05-28T17:00:00",
"timeZone": "Pacific Standard Time"
},
"location": {
"displayName": "Mi casa"
},
"attendees": [{
"emailAddress": {
"address": "email",
"name": "name"
},
"type": "required"
}]
}
Your attendees collection however is rendering as an object instead of an array. It is rendering your attendees as an object instead of an array. This is likely the cause of that payload error.
"attendees": {
"emailAddress": {
"address": "email",
"name": "name"
},
"type": "required"
}
Please note, I'm not a PHP expert so my code here may be rather inelegant. That said, I believe you can ensure it renders as an array by wrapping it in an additional array():
'attendees'=>array(array(
'emailAddress'=>array('address'=>'email', 'name'=>'name'),
'type'=>'required'
)),

Here is the PHP example:
"attendees" => [ array (
"emailAddress" => array(
"address" => "user#domain.com",
"name" => "User's first and last name",
),
"type" => "required",
)],

Related

Cannot retreive virtual card number in test mode via stripe API using Go examples

Trying to follow the example here: https://stripe.com/docs/issuing/cards/virtual
When I add params.AddExpand("number"), no number is returned, yet via the dashboard I was able to see the card numbers. Here's sample code and redacted info for the Req and Resp.
func (ac *appContext) CardRetrieve(id string) *stripe.IssuingCard {
stripe.Key = ac.Config.Stripe.SecretKey
params := stripe.IssuingCardParams{}
params.AddExpand("number")
params.AddExpand("cvc")
ic_num, _ := card.Get(id, &params)
return ic_num
}
Returns:
{
"id": "ic_redacted",
"object": "issuing.card",
"brand": "Visa",
"cancellation_reason": null,
"cardholder": {
"id": "ich_redacted",
"object": "issuing.cardholder",
"billing": {
"address": {
"city": "A Beach",
"country": "US",
"line1": "404 Main St.",
"line2": "Suite #302",
"postal_code": "19001",
"state": "DE"
}
},
"company": null,
"created": 1613338532,
"email": "redacted#notreal.com",
"individual": {
"dob": {
"day": 20,
"month": 10,
"year": 1990
},
"first_name": "User",
"last_name": "Testing",
"verification": {
"document": {
"back": null,
"front": null
}
}
},
"livemode": false,
"metadata": {
},
"name": "User Testing",
"phone_number": "+15165551212",
"requirements": {
"disabled_reason": "under_review",
"past_due": [
]
},
"spending_controls": {
"allowed_categories": [
],
"blocked_categories": [
],
"spending_limits": [
{
"amount": 1,
"categories": [
],
"interval": "daily"
}
],
"spending_limits_currency": "usd"
},
"status": "active",
"type": "individual"
},
"created": 1613338532,
"currency": "usd",
"exp_month": 1,
"exp_year": 2024,
"last4": "0088",
"livemode": false,
"metadata": {
},
"replaced_by": null,
"replacement_for": null,
"replacement_reason": null,
"shipping": null,
"spending_controls": {
"allowed_categories": null,
"blocked_categories": null,
"spending_limits": [
{
"amount": 1,
"categories": [
],
"interval": "daily"
}
],
"spending_limits_currency": "usd"
},
"status": "inactive",
"type": "virtual"
}
What confuses me is the documentation found here:
https://stripe.com/docs/issuing/cards/virtual
It says: You can retrieve both the full unredacted card number and CVC from the API. For security reasons, these fields are only available for virtual cards and will be omitted unless you explicitly request them with the expand property. Additionally, they are only available through the Retrieve a card endpoint. That links to the issue card retrieval end point, but the params defined in the virtual cards example references the CardParams{} struct.
No of the examples show what imported module their aliasing for card to exec card.Get, but it stands to reason given the flow of the documentation that this should be IssuingCardParams{} and that the card alias is referencing: "github.com/stripe/stripe-go/issuing/card"
I also find it strange that we're defining params in the example but not passing it into the card.Get()
Edit:
I went digging through the module and it seems like to get the card details you have to call: details, _ := card.Details(id, params) but I get a 404 when trying to call that. The object returned is actually the right object and I see number and cvc, albeit nil.
I get the following error:
2021/02/15 00:33:06 Request error from Stripe (status 404): {"status":404,"message":"Unrecognized request URL (GET: /v1/issuing/cards/ic_redacted/details). Please see https://stripe.com/docs
So it seems you need to include a /v72 in the import:
"github.com/stripe/stripe-go/v72"
The documentation should be updated to show this and the virtual card example for go should also be updated.

JIRA API Error: 'It is not on the appropriate screen, or unknown' when calling Create Issue endpoint

I met an issue when I call the create issue API in my code, the error is It is not on the appropriate screen, or unknown.' But when trying the test API with the same parameters in postman, it succeeds, is there anyone who knows the reason for this error?
This is my code:
create_url = "https://myjira/rest/api/2/issue/"
jira_hash =
{
"fields": {
"project": {
"id": "51606"
},
"issuetype": {
"name": "SOAK EVENT"
},
"priority": {
"name": "Critical"
},
"labels": ["Chandler"],
"customfield_10012": {
"id": "10006"
},
"fixVersions": [{
"name": "2019-05-r1"
}],
"summary": "10297",
"description": "description"
}
}
HTTParty.post(create_url,
:body => jira_hash.to_json,
:headers => {'Content-Type' => 'application/json', 'Authorization'
=> auth})

Bug: findMeetingTimes throws “AttendeesUnavailable” even for optional attendees

I'm trying to use the https://outlook.office.com/api/v2.0/me/findmeetingtimes endpoint documented on the MSDN Outlook Calendar website. When I call the endpoint with the following payload:
{
"Attendees": [
{
"Type": "optional",
"EmailAddress": {
"Name": "Studio 3",
"Address": "PDXICSTUDIO3#rogueInc.onmicrosoft.com"
}
}
],
"TimeConstraint": {
"ActivityDomain":"Unrestricted",
"Timeslots": [
{
"Start": {
"DateTime": "2018-10-30T19:30:00",
"TimeZone": "UTC"
},
"End": {
"DateTime": "2018-10-30T20:30:00",
"TimeZone": "UTC"
}
}
]
},
"ReturnSuggestionReasons": "true",
"IsOrganizerOptional": false,
"MaxCandidates": 99
}
I get an empty meeting time suggestions response with the reason provided as "AttendeesUnavailable". It doesn't seem to matter whether I declare the type of the attendee as "optional", "required", or "resource" as specified in the attendeeBase Resource Type documentation. This seems like a bug with the GraphAPI and I'm unsure as to how to proceed.

swagger: how to validate formData

So far I'm able to do swagger validation if the parameters are from "in": "body" or if the input expected is in a json format.
However, I can't find how to validate a simple string entered as formData.
Below is my swagger script (in json format)
v1swag = {
"cancels_post": {
"tags": ["/api/v1"],
"parameters": [
{
"name": "token",
"in": "formData",
"type": "string",
"required": True,
"description": "Cancels the provided token.",
}
],
"responses": {
"200": {
"description": "Success!",
}
}
}
}
I removed the schema as it seems to only work for "in": "body"
I've been searching the net but can't seem to find the light.
Though I will still be searching... Any hints would be greatly appreciated.
Thank you very much in advance.
A different source media type has to be consumed here. Specify "consumes" member to include media type of application/x-www-form-urlencoded.
v1swag = {
"cancels_post": {
"tags": ["/api/v1"],
"consumes": [
"application/x-www-form-urlencoded"
],
"parameters": [
{
"name": "token",
"in": "formData",
"type": "string",
"required": True,
"description": "Cancels the provided token.",
}
],
"responses": {
"200": {
"description": "Success!",
}
}
}
}

Parsing out multiple API JSON response parameters

I'm getting a JSON response back from an API, however the response has several key parameters all called 'jacket' with different values. I am able to parse out the first key but I don't get the rest of the values. Here is some of the code, I might be approaching this the wrong way:
parsed_list = JSON.parse(get_response.body)
orig = parsed_list["_links"]["stuff"]["orig"]
serv = parsed_list["_links"]["stuff"]["serv"]
puts orig.first["jacket"]
puts serv.first["jacket"]
=> 123456789
=> 987654321
This is what the JSON response looks like before I parse it out and set it "parsed_list"
"_links": {
"self": {
"href": "url"
},
"stuff": {
"href": "url",
"orig": [
{
"jacket": "123456789",
"Id": "x",
"selected": true,
}
],
"serv": [
{
"jacket": "987654321",
"Id": "xx",
"selected": false,
},
{
"jacket": "0000000001",
"Id": "xx",
"selected": false,
},
{
"jacket": "1111111110",
"Id": "xx",
"selected": false,
}
]
}
}
}
I need to be able to extract all of the "jacket" values.
The data's right there, you just need to get it:
serv.collect do |entry|
entry['jacket']
end

Resources