Issue
I'm trying to build a little script PHP to integrate with the Microsoft Graph API.
I have an admin account in Azure, and have set up a new app through the portal. I've downloaded and installed the PHP SDK, and have managed to set everything up so that I can get a user successfully.
However, POSTing a new user returns me a 400 bad request:
$newUser = new User();
$newUser->setAccountEnabled(true);
$newUser->setGivenName('name');
$newUser->setSurname('surname');
$newUser->setUserPrincipalName('email#dot.com');
$password = new PasswordProfile();
$password->setPassword("pwd");
$password->setForceChangePasswordNextSignIn(false);
$newUser->setPasswordProfile($password);
$identities = new ObjectIdentity();
$identities->setSignInType("emailAddress");
$identities->setIssuer("a tenantId");
$identities->setIssuerAssignedId("email#dot.com");
$newUser->setIdentities($identities);
$user = $this->graph->createRequest('POST', '/users')
->attachBody($newUser)
->setReturnType(Model\User::class)
->execute();
Returns:
{"error":{"code":"BadRequest","message":"Property identities in payload has a value that does not match schema.","innerError":{"date":"2021-11-15T15:26:24","request-id":"an id","client-request-id":"an id"}}}
How can I solve this issue?
Thanks for any help.
Update
I have found a solution for this problem (obviously, is temporary).
The section "identities" must be set as an array (in JSON) like in this example
"identities": [
{
"signInType": "emailAddress",
"issuer": "contoso.onmicrosoft.com",
"issuerAssignedId": "jsmith#yahoo.com"
}
]
Probably, the PHP code above not set the section "identities" as an array.
Now, I send directly a JSON with the section "identities" as an array but I would like to use the PHP code above.
How can I transform the PHP code above to pass "identities" as an array like in the JSON example?
Thanks again.
Try creating an array and adding the identities on there like. This will add the identities property as an array of Model\ObjectIdentity()
...
$identities = [];
$identity = new Model\ObjectIdentity();
$identity->setSignInType("type");
$identity->setIssuer("issuer");
$identity->setIssuerAssignedId("issure-assigned-id");
array_push($identities, $identity);
$newUser->setIdentities($identities);
...
Related
I'm having some problems with my Shopify 'orders/paid' webhook that I install onto the users store via the Shopify SDK (using a PHP wrapper: https://github.com/phpclassic/php-shopify). Anyways, I create the webhook like so:
$shop = $this->request->getVar('shop'); // Get Shopify store URL
// Get access token for store
$config = array('ShopUrl' => $shop, 'ApiKey' => 'xxx', 'SharedSecret' => 'xxx');
\PHPShopify\ShopifySDK::config($config);
$accessToken = \PHPShopify\AuthHelper::getAccessToken();
// Keep track of access_token for SDK calls and authenticate to store for webhook creation
$addToken = $this->Stores->addAccessToken($shop, $accessToken);
$config = array('AccessToken' => $accessToken, 'ShopUrl' => $shop);
$shopify = new \PHPShopify\ShopifySDK($config);
// Create orders/paid webhook
$orderPaidHook = array('topic' => 'orders/paid', 'address' => 'https://api.autoloapp.com/webhook/create', 'format' => 'json');
try {
$webhooks = $shopify->Webhook->post($orderPaidHook);
}
This code as far as I can tell works, using print_r($webhooks) gives me a valid Webhook that has (in theory) been installed on to the store. However, when an order is actually paid for on the store I DO NOT get a message.
Using the "Test Webhook" settings under "Notification" in the Shopify Admin my webhook works perfectly. Using PostMan to simulate a webhook call works perfectly.
The code to process the webhook looks like this:
$headers = getallheaders();
$topic = $headers['X-Shopify-Topic'];
$storeName = $headers['X-Shopify-Shop-Domain'];
if ($topic == 'orders/paid') {
// Do some stuff, insert row into database
}
Again, when I use PostMan or the built-in "Test Webhook" setting for Shopify the row in my database gets created just fine. When I do it with a real webhook nothing happens. I'm not sure why this is happening, as far as I know all the headers should be the same. Do I need to verify the webhook in some way?
For reference I'm using CodeIgniter 4.0, PHP 7.0, and the newest version of the Shopify SDK.
I found this note on Shopify's Docs: "Note that if you are using a Rack based framework such as Ruby on Rails or Sinatra the header you are looking for is HTTP_X_SHOPIFY_HMAC_SHA256". With my current set-up I should still be using X-Shopify-Shop-Domain instead of HTTP_X_Shopify_Shop_Domain correct? Any help greatly appreciated!
So I finally figured out that for some reason the 'orders/paid' webhook wouldn't work for me in "production environments" despite working fine in my test environments. Simply changing the topic to 'orders/create' resolved my problem.
I created one service account with role big query admin.I am Using big query PHP API. Let me know if any other permission is required or not?
It gives me an error stating that the:
service account does not have bigquery.jobs.create permission.
I wanted to run a query on bigquery. Please help.
Following is my code:
$service = new Google_Service_Bigquery($client);
$query = new Google_Service_Bigquery_QueryRequest($client);
$query->setQuery('SELECT * FROM [xxx:xxx.xxs] LIMIT 1000;');
$jobs = $service->jobs;
$response = $jobs->query($project_id, $query);
// Do something with the BigQuery API $response data
print_r($response)
;
I ran into this problem using the BQ library for nodejs.
It seems being signed into a user/service account via the CLI is not always enough. My service account was authenticated and had the correct permissions in the GCP SDK Shell, but I still got service account does not have bigquery.jobs.create permission..
I was able to fix this by simply adding the same service account details, using the client library methods. I used https://googleapis.dev/nodejs/bigquery/latest/BigQuery.html.
In the case of nodejs, I just had to add
// Imports BigQuery library
const {BigQuery} = require('#google-cloud/bigquery');
// Create BQ Options - this object is what fixed the issue
const bqOptions = {};
bqOptions.projectId = '*your-project-name*';
bqOptions.keyFilename = '*Path-to-service-account-private-key*';
// Creates BQ client
const bq = new BigQuery(bqOptions);
I know you are using the PHP library, but I think the PHP equivalent would work the same.
I'm attempting to use the SoftLayer API (via the PHP client) to add an update to an existing ticket, as a specific user under our main account (a sibling to our API user).
What I'm trying to achieve is that as the API user, I call SoftLayer_Ticket::addUpdate, passing a SoftLayer_Ticket_Update object that looks similar to:
{
editorID: user1_id_here,
editorType: "USER",
entry: 'My update here'
}
I have user1's ID, however when I pass it in the SoftLayer_Ticket_Update object, the update is still attached as the API user:
{
createDate:"2016-05-17T08:24:50-07:00"
editorId:api_users_id
editorType:"USER"
entry:"Another update for our glorious leader..."
id:#########
ticketId:########
}
Snippet of the ticket update code:
$slClient = \SoftLayer_client::getClient("Ticket", $ticketID);
$ticketUpdateObj = new \stdClass();
$ticketUpdateObj->entry = $update;
$ticketUpdateObj->editorId = ######;
$ticketUpdateObj->editor = ######;
$ticketUpdateObj->editorType = "USER";
$result = $slClient->addUpdate($ticketUpdateObj);
...
(do other stuff here)
Is there any way to do this with the SoftLayer API? Or is the issue stemming from permissions given to the API user, or that I'm attempting to add the update as a sibling to the API user? Any help would be appreciated!
Our platform is older, so we are using an older version of the SoftLayer PHP SOAP client (guessing circa 2010/early 2011).
Thank you in advance!
Sorry, that is not possbile you cannot set the editorId, this value is set by the system with the userID of the user who updated the ticket.
Regards
I've been taking a look at the Google API PHP Client and would like to use it to add rows to a Google Sheet. From the code, it looks like one would use this method:
public function insert($fileId, Google_Service_Drive_Property $postBody, $optParams = array())
{
$params = array('fileId' => $fileId, 'postBody' => $postBody);
$params = array_merge($params, $optParams);
return $this->call('insert', array($params), "Google_Service_Drive_Property");
}
but I can't really tell what the parameters would be. Am I heading in the right direction? Also, not quite sure on how to connect to a specific Sheet. Please advise.
Thanks!
Use Google sheets class from zend framework 1.12. They have very nicely coded library for Google Spreadsheets
https://github.com/zendframework/zf1/tree/master/library/Zend/Gdata/Spreadsheets
I figured out how to work this and wanted to share with you guys. As I stated in a comment, I did not think using Zend's GData class was a good way for me since it's very dependent on other classes throughout the framework, thus being too heavy.
So I ended up using this Spreadsheet Client on top of Google's API. Google's API is used to authenticate my service, then I start calling the Spreadsheet Client library afterwards.
After spending over a day of Googling for various problems I had for the authentication process, here's what I did to make things work:
Created a new project for Google API here
Clicked "APIs" menu on the left side under "APIs & Auth"
Searched the Drive API and enabled it (can't remember if it was necessary)
Clicked the "Credentials" menu on the left
Clicked "Create new Client ID" button under OAuth
Selected "Service Account"
After info showed & json downloaded (not needed), I clicked "Generate new P12 Key" button
I saved the p12 file somewhere I could access it through PHP
Then in the code, I added the following lines:
$email = 'somethingsomethingblahblah#developer.gserviceaccount.com';
$CLIENT_ID = $email;
$SERVICE_ACCOUNT_NAME = $email;
$KEY_FILE = 'path/to/p12/file';
$SPREADSHEETS_SCOPE = 'https://spreadsheets.google.com/feeds';
$key = file_get_contents($KEY_FILE);
$auth = new Google_Auth_AssertionCredentials(
$SERVICE_ACCOUNT_NAME,
array($SPREADSHEETS_SCOPE),
$key
);
$client = new Google_Client();
$client->setScopes(array($SPREADSHEETS_SCOPE));
$client->setAssertionCredentials($auth);
$client->getAuth()->refreshTokenWithAssertion();
$client->setClientId($CLIENT_ID);
$accessToken = $client->getAccessToken();
Also, I had to make sure I:
Shared my spreadsheet specifically with the email address on my service account in the code above
Synced my server's time (I'm running Vagrant CentOS so it's slightly different)
I believe you can run this code with other services beyond Spreadsheets, such as Youtube, Analytics, etc., but you will need to get the correct scope link (see $SPREADSHEETS_SCOPE above). Remember, this is only when using the Service Account on the Google Console, which means you are programmatically getting data from your code. If you are looking to have others users sign in using the API, then it's different.
I need to insert user's email in postBody of mirror API insert method. I am using this code:
$authtoken=null;
$postBody = new Google_Service_Mirror_Account();
$postBody->setAuthTokens($authtoken);
$userdata=array("email"=>$email);
$postBody->setUserData($userdata);
$account = $service->accounts->insert($userToken, package-name-here, $accountName, $postBody);
The above method returns null in response! I am not sure what to add as authtoken.
After this, I need to retrieve user's email account through Android's account manager:
AccountManager manager = AccountManager.get(c);
Account[] list = manager.getAccountsByType(package-name-here);
for (Account acct : list) {
accountEmailId= manager.getUserData(acct, "email");
break;
}
This doesn't seem to work. I do not get accounts of this type in Glass device. Any help will be great.
EDIT:
Added the authTokenArray and userDataArray to postBody as suggested below:
$userDataArray= array();
$userData1= new Google_Service_Mirror_UserData();
$userData1->setKey('email');
$userData1->setValue($email);
$userDataArray[]=$userData1;
$authTokenArray= array();
$authToken1= new Google_Service_Mirror_AuthToken();
$authToken1->setAuthToken('randomtoken');
$authToken1->setType('randomType');
$authTokenArray[]=$authToken1;
$postBody = new Google_Service_Mirror_Account();
$postBody->setUserData($userDataArray);
$postBody->setAuthTokens($authTokenArray);
Account insert method still returns null. Unable to solve the issue till now.
[SOLVED]
Mirror API still returns NULL response, but account is actually being inserted in Mirror API. Updated code can be viewed here: http://goo.gl/DVggO6
setAuthTokens takes an array of Google_Service_Mirror_AuthToken objects (see the source here), each of which has an authToken (an arbitrary string of your choosing) and a type (another arbitrary string). These values are copied directly into the account in the Android AccountManager so that you can look them on the device.
Your problem might be coming from the fact that you're passing in null for that right now. I would try fixing that and then see if you're able to see the account on the device.