I used Microsoft Graph API PHP SDK to add user in my Azure Active Directory B2C. I managed to create users with a userPrincipalName like name#mytenantid.onmicrosoft.com.
I wasn't able to add users with a GMail address such as john.doe#gmail.com.
I tried to add the signInNames collection but I got the following response:
Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error:
POST https://graph.microsoft.com/v1.0/users resulted in a 400 Bad Request
response:
{ "error": {
"code": "Request_BadRequest",
"message": "Invalid property 'signInNames'.",
"innerError": (truncated...)
Here is my JSON request body :
{
"accountEnabled": true,
"displayName": "John Doe",
"userPrincipalName": "john#doe.fr",
"creationType": "LocalAccount",
"passwordProfile" : {
"forceChangePasswordNextSignIn": true,
"password": "P#!ssWor?D"
},
"signInNames": [
{
"type": "emailAddress",
"value": "john#doe.fr"
}
]
}
You're confusing Microsoft Graph API with the Azure AD Graph API. These are two different APIs. While they share a lot of functionality, calls to these APIs are not interchangeable.
The User object in Microsoft Graph API doesn't support a signInNames property. This is why it is returning that error.
Local account users are not supported by Microsoft Graph API at the moment.
In case if someone will still have the same problem, in MS Graph Api you can use "identities" instead of "signInNames" and your JSON will look like
{
"accountEnabled":true,
"displayName":"John Doe",
"userPrincipalName":"john#doe.fr",
"creationType":"LocalAccount",
"passwordProfile":{
"forceChangePasswordNextSignIn":true,
"password":"P#!ssWor?D"
},
"identities":[
{
"signInType":"emailAddress",
"issuer":"<your tenant domain name>",
"issuerAssignedId":"john#doe.fr"
}
]
}
Related
I'm not sure if this is an inconsistency of YouTube's Data API or just a bad naming of a YouTube error.
There's a public channel on YouTube without any content:
https://www.youtube.com/channel/UCvAHk_1_TMmq6SW0XA9BcgA.
If I query Channels:list (query) with this channel ID UCvAHk_1_TMmq6SW0XA9BcgA, I get the following response:
{
"items": [
{
"id": "UCvAHk_1_TMmq6SW0XA9BcgA",
"snippet": {
"title": "level10store0"
},
"status": {
"privacyStatus": "public",
"isLinked": true,
"longUploadsStatus": "longUploadsUnspecified"
}
}
]
}
If I query for all playlists of this channel via Playlists:list (query) I get this response:
{
"kind": "youtube#playlistListResponse",
"etag": "iziRvpOe3rkNWHlySTxLgAk4dJI",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": []
}
But using YouTube's PHP client with Playlist:list you'll get a response error with following information:
domain=youtube.playlist, reason=channelNotFound, location=channelId,
locationType=parameter
Why does YouTube's PHP client give a channelNotFound error instead of an empty response like YouTube's data explorer does?
Update 1:
YouTube's data API delivered a channel on the OAuth handshake initialized by the user itself. My application asked for an offline access token for further requests. If I use this access token I experience the above mentioned behaviour. I think the token is valid as I use the identical process for many other users. If the token would not be valid I would have got an error message like global.authError or youtube.header.youtubeSignupRequired.
My code looks like this (which works for many other users):
$youtubeClient->playlists->listPlaylists(
'snippet,contentDetails',
array(
'maxResults' => 50,
'channelId' => $channelId,
'pageToken' => $nextPlaylistPageToken,
'fields' => 'etag,items(id,etag,snippet(publishedAt,channelId,thumbnails/default,title),contentDetails(itemCount)),nextPageToken'
)
);
Remember that YouTube is channel based and not user based. When the user logs in they pick which channel to access. When the user consented access to your application on PHP they did not pick the correct channel so there for do not have access to the data on that channel.
Log the user out and consent access again this time picking the correct channel.
I want to create contacts with outlook in my application.Firstly, I get into this url below
https://login.live.com/oauth20_authorize.srf?client_id='.$client_id.'&scope=wl.signin%20wl.basic%20wl.emails%20wl.contacts_emails%20wl.contacts_create&response_type=code&redirect_uri='.$redirect_uri
I hope this is an old way to get the token,so I am
https://login.microsoftonline.com/daa825ce-e4fb-40d2-b2e6-3a2f25e62b7c/oauth2/token?client_id='.$client_id.'&scope=wl.signin%20wl.basic%20wl.emails%20wl.contacts_emails%20wl.contacts_create&response_type=code&redirect_uri='.$redirect_uri
So I get this error below.
http://prntscr.com/p4mb2c
To create contacts, you should call
POST https://graph.microsoft.com/v1.0/me/contacts
Content-type: application/json
{
"givenName": "Pavel",
"surname": "Bansky",
"emailAddresses": [
{
"address": "pavelb#fabrikam.onmicrosoft.com",
"name": "Pavel Bansky"
}
],
"businessPhones": [
"+1 732 555 0102"
]
}
You can follow this document to get the access token. Remember to grant your application Contacts.ReadWrite permission.
The scope in steps2&step3 should be https://graph.microsoft.com/Contacts.ReadWrite
Update:
To use personal account, you need to set the supported account type like below
And the authorize endpoint should use common, not the specified tenant.
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?
client_id=562855f4-f3dd-40bb-b829-515ccb96ff3f
&response_type=code
&redirect_uri=http://localhost
&response_mode=fragment
&scope=https://graph.microsoft.com/Contacts.ReadWrite
&state=12345
Also the token endpoint.
https://login.microsoftonline.com/common/oauth2/v2.0/token
I am using Microsoft Graph Library for PHP (microsoftgraph/msgraph-sdk-php) to save documents in Onedrive for Business.
I am having issues to create items (folders or upload files) using Microsoft Graph API, for instance, when I am creating folders I am getting:
"Client error: `POST https://graph.microsoft.com/v1.0/drives/MYDRIVEID/items/MYPARENTFOLDERID/children` resulted in a `400 Bad Request` response: { "error": { "code": "invalidRequest", "message": "One of the provided arguments is not acceptable.", "innerError": { "request-id": "bec1d260-3efd-4417-ba80-96ec37078df6", "date": "2018-07-20T16:48:34" } } } "
POST
https://graph.microsoft.com/v1.0/drives/MYDRIVEID/items/MYPARENTFOLDERID/children
body:
{"name":"Project1","folder":{}}
This is the code I am executing:
$graph->createRequest("POST","/drives/$driveId/items/$itemId/children")-
>attachBody($body)->setReturnType(Model\DriveItem::class)->execute();
My guess is that the API is expecting something different than I am sending, I have tried to change the body, for instance:
{"name":"Project1","folder":{"childCount":0}}
{"name":"Project1","folder":{},"#microsoft.graph.conflictBehavior":"rename"}
{"name":"Project1","folder":{"childCount":0},"#microsoft.graph.conflictBehavior":"rename"}
but I am still getting the same error.
I am not sure what I am doing wrong
Any ideas?
Thanks in advance for your help
I deleted the app registration and registered it again in azure portal. Create folder operation is working as expected.
I'm sending the following request to the Google Datastore API, via the PHP client, and i'm getting a "503 Backend Error" without any other information. I tried the online client available here, but the error is the same. Maybe something is malformed on my request? The documentation wasn't very helpful:
{
"mode": "NON_TRANSACTIONAL",
"mutation": {
"upsert": [
{
"key": {
"path": [
{
"kind": "Log"
}
]
},
"properties": {
"event": {
"indexed": false,
"stringValue": "new_order"
},
"dataType": {
"indexed": false,
"stringValue": "test"
}
}
}
]
}
}
Any ideas of what might be causing this behavior? Or how to enable more detailed feedback from the API?
When you perform POST https://www.googleapis.com/datastore/<APIversion>/datasets/<datasetId>/commit, make sure that if you created your project using the old Admin Console that your datasetId in the URL is the App Engine application ID, and that if you created your project using the Developer Console, that your datasetId is the project ID you see in the Developer Console.
Also, if you created your project through the new Developer Console, try toggling the API on and off.
Finally, check that you are completing the OAuth flow properly, all your client ID info makes sense, and that you are setting up the right scopes, etc...
Since Youtube Api V2 doesn't support like a specific video anymore. Can anyone please explain how to like a video with youtube api v3 ?
I am always getting the following response:
Response
400 Bad Request
- Show headers -
{
"error": {
"errors": [
{
"domain": "youtube.part",
"reason": "unexpectedPart",
"message": "contentDetails",
"locationType": "parameter",
"location": "part"
}
],
"code": 400,
"message": "contentDetails"
}
}
The request is :
Request
POST https://www.googleapis.com/youtube/v3/activities?part=snippet&key={YOUR_API_KEY}
Content-Type: application/json
Authorization: Bearer ya29.AHES6ZQUI8Gn7j93QZBmmdlDe7Ei-iqYseYAKAxyf3qTOHHwDHb-dA
X-JavaScript-User-Agent: Google APIs Explorer
{
"contentDetails": {
"like": {
"resourceId": {
"videoId": "video-id",
"kind": "youtube#video"
}
}
}
}
The part is = snippet
I am following these docs : https://developers.google.com/youtube/v3/docs/activities/insert
The answer is already in the comments, but to elevate it a bit: YouTube API v3: Liking a video in Python has more information about liking a video, though the example there is in Python.
The important part is that liking a video is done via a playlistItems.insert() call, not an activities.insert() call. This is a common source of confusion and I've already asked our tech writer to try to clear things up in the docs.