Microsoft Graph - POST request error 20132 - php

I can't seem to get a POST request to create assignments using Microsoft Graph.
Both in the Graph Explorer and in PHP I get the same error: "message": "The content of the request is invalid. Common causes are an invalid Content-Type header or no content in the body.",
Endpoint: https://graph.microsoft.com/beta/education/classes/class-id/assignments
Request Headers: content-type: application/json
Body:
{
"dueDateTime": "2014-02-01T00:00:00Z",
"displayName": "Midterm 1",
"instructions": {
"contentType": "Text",
"content": "Read chapters 1 through 3"
},
"grading": {
"#odata.type": "#microsoft.education.assignments.api.educationAssignmentPointsGradeType",
"maxPoints": 100
},
"assignTo": {
"#odata.type": "#microsoft.education.assignments.api.educationAssignmentClassRecipient"
},
"status":"draft",
"allowStudentsToAddResourcesToSubmission": true
}
Any help would be truly appreciated!
Please see image of Graph Explorer below.

Figured it out. Removing the "contentType": "Text" attribute from instructions worked.

Related

400 Error Invalid Recipient Err Microsoft Graph API

I am trying send email through Microsoft graph api. I created a message object like the following.
{"message":{"subject":"hellowolrd","body":{"contentType":"text","content":"wow"}},"toRecipients":{"emailAddress":{"address":"example#yahoo.com"}}}
But gets 400 error with invalid recipient. Can anybody help me why I am getting this error.
It seems you have a syntax issue in your JSON request.Look closely after content you have an extra closing } which means you are not posting 'toRecipients' in the message.
{"message":{"subject":"hellowolrd","body":{"contentType":"text","content":"wow"}},"toRecipients":{"emailAddress":{"address":"example#yahoo.com"}}}
Instead try below JSON to make it work -
{
"message": {
"subject": "hellowolrd",
"body": {
"contentType": "text",
"content": "wow"
},
"toRecipients": [
{
"emailAddress": {
"address": "example#yahoo.com"
}
}
]
}
}
Thanks!
The invalid recipient was caused by a different json structure. I had to exactly match the following structure that was provided in one of their example.
$mailArgs ='
{
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "Text",
"content": "Lunch Invited"
},
"toRecipients": [
{
"emailAddress": {
"address": "example#example.com"
}
}
]
}
}';
So I created a JSON array to match exactly the same structure and it worked!

API gives 406 code with Accept application/json request : Bluehost

This is the result I get when I try to validate my API.
Content-Type: application/json
Vary: Accept
{
"valid": false,
"token_uri": "https://mining4btc.com/NFT/rinkeby/CKE/1",
"errors": [
"InvalidTokenUrlResponseException: Invalid response, expected 200 but got 406 for URL: https://mining4btc.com/NFT/rinkeby/CKE/1"
]
}
I'm using this to validate my API:
https://testnets-api.opensea.io/asset/0xe8dD349E3B0F0FA0eE063a2D99541155aFEf14B9/1/validate/
As you can see, it's getting a 406 code.
This is the API:
<?php
header('Content-Type: application/json');
$output = '{
"attributes": [
{
"trait_type": "Eyes",
"value": "cute"
},
{
"trait_type": "Nose",
"value": "cute"
},
{
"trait_type": "Cheeks",
"value": "cute"
},
{
"trait_type": "Toes",
"value": "cute"
},
{
"trait_type": "Ability",
"value": "chairs"
},
{
"display_type": "boost_number",
"trait_type": "Cuteness",
"value": 5000
},
{
"display_type": "number",
"trait_type": "Age",
"value": 1
}
],
"description": "Thinking about my Mommy.",
"external_url": "https://mining4btc.com/NFT/rinkeby/CKE/external",
"image": "https://mining4btc.com/NFT/rinkeby/CKE/proof/1.jpg",
"name": "Chillin"
}';
$decoded = json_decode($output);
echo json_encode($decoded);
?>
This is a contract API for a NFT following the OpenSea documents; deployed with Truffle to rinkeby.
I have confirmed that this is because Bluehost actively blocks (by returning this code) requests with Accept:application/json headers. You have to contact Bluehost and ask them to whitelist the IP addresses that you want to be able to access the metadata.
As far as I can tell, they do this because they want to push people to pay for a VPS, because they are assuming this kind of request would go to some kind of robust API that requires significant backend processing.

How can I send push notification from PHP website to iOS and Android?

How I can send push notification from PHP website to iOS devices and Android devices?
Is there any tutorial for that?
You can use several premade services for push notifications like Firebase Messaging, One Signal, etc. For Firebase cloud Messaging Integration with PHP, please visit this Link. After setting up, Just Send this POST request with the user token
POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...PbJ_uNasm
{
"message": {
"token" : <token of destination app>,
"notification": {
"title": "FCM Message",
"body": "This is a message from FCM"
},
"webpush": {
"headers": {
"Urgency": "high"
},
"notification": {
"body": "This is a message from FCM to web",
"requireInteraction": "true",
"badge": "/badge-icon.png"
}
}
}
}
or Send a Push Notification using topic
https://fcm.googleapis.com//v1/projects/<YOUR-PROJECT-ID>/messages:send
Content-Type: application/json
Authorization: bearer <YOUR-ACCESS-TOKEN>
{
"message": {
"topic": "matchday"
"notification": {
"title": "Background Message Title",
"body": "Background message body"
},
"webpush": {
"fcm_options": {
"link": "https://dummypage.com"
}
}
}
}
For One Signal, Visit this Link for more information. Also, alternatively, you can use web sockets, if you don't want premade services.

POST JSON Object with multiple headers in php

Request header
Content-Type: application/json
Authorization: Bearer [access token]
Accept: application/json
if send unicode string with message, please set Content-Type charset to UTF-8
Following is a sample request of send service.
URL-https://example.com/requests
Method - POST
Body
{
"outboundSMSMessageRequest": {
"address": [
"tel:+94771234567"
],
"senderAddress": "tel:12345678",
"outboundSMSTextMessage": {
"message": "Test Message"
},
"clientCorrelator": "123456",
"receiptRequest": {
"notifyURL": "http://128.199.174.220:1080/sms/report",
"callbackData": "some-data-useful-to-the-requester"
},
"senderName": "ACME Inc."
}
}
How to post and get responce
ajax
headers: {
'X-HTTP-Method-Override': 'POST',
'Content-Type': 'application/json'
},
or vanilla js
How to create javascript POST request to server with Headers and Data

Regarding stackify-api, data not displaying in stackify logs

Currently, I am using a trial version.When hit from the php code using the monolog and syslog, the logs are displayed in the stackify log management console.But as mentioned in
https://github.com/stackify/stackify-api/blob/master/endpoints/POST_Log_Save.md
When I hit using POSTMAN tool, the response I receive is
{
"success": true,
"took": 46
}
But the logs are not displayed in the stackify logs console.
My postman request headers:
Content-Type,Accept,X-Stackify-PV,X-Stackify-Key are provided.
Body:
{
"Env": "Prod",
"ServerName": "rajeshwar-latitude-3450",
"AppName": "Stackifytest",
"Msgs": [
{
"Msg": "debug message",
"Level": "DEBUG"
},
{
"Msg": "info message",
"Level": "DEBUG"
}
]
}
I'm pretty sure the EpochMs field is required.
Please check the readme file. It says which fields are required.
https://github.com/stackify/stackify-api/blob/master/endpoints/POST_Log_Save.md

Categories