Update user password via REST Drupal 8.x - php

I am using Drupal 8.3.x.
The simple requirnment is like, user need to update his password by entering his old and new password.
By Google I found this link and using it but I am not understand how to send new password?
HTTP request is like this.
Method:
PATCH
HEADER:
Authorization:Bearer <token>
Content-Type:application/hal+json
Body:
{
"_links": {
"type": {
"href": "{domain}/rest/type/user/user"
}
},
"pass": [
{"existing":"testpass"}
]
}
Now how to set new password here?

Analogously to updating mail action
{
"_links": {
"type": {
"href": "{domain}/rest/type/user/user"
}
},
"pass":[{"existing":"testpass"}],
"mail":{
"value":"updatedtestuser#mailserver.com"
}
}
it should be sth like
{
"_links": {
"type": {
"href": "{domain}/rest/type/user/user"
}
},
"pass": [
{"existing":"testpass", "value": "newpass"}
]
}

Related

LinkedIn API UGC post success but not showing?

I believe I am successfully posting a new post to the endpoint
https://api.linkedin.com/v2/ugcPosts
using (similar to)
{
"author": "urn:li:organization:1234567",
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"attributes": [],
"text": "Some share text"
}
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
The response I get is
{"id":"urn:li:share:01234567890123456789"}
But then when I go to the company page, the post is not visible. Note that the IDs are redacted here. Is there another step I have to take?
edit: I went to verify the post with the endpoint https://api.linkedin.com/v2/ugcPosts/[redacted URN]?viewContext=AUTHOR and my post is a success
{
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"inferredLocale": "en_US",
"attributes": [],
"text": "Test article sharing article on LinkedIn API , please ignore"
},
"media": [
{
"media": "urn:li:digitalmediaAsset:XXXXXXXXXXXXXX",
"title": {
"attributes": [],
"text": "image"
},
"thumbnails": [],
"status": "READY"
}
],
"shareFeatures": {
"hashtags": []
},
"shareMediaCategory": "IMAGE"
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
},
"created": {
"actor": "urn:li:person:XXXXXXXXXXXXXX",
"time": 1649285262053
},
"author": "urn:li:organization:XXXXXXXXXXXXXX",
"clientApplication": "urn:li:developerApplication:XXXXXXXXXXXXXX",
"versionTag": "0",
"id": "urn:li:share:XXXXXXXXXXXXXX",
"firstPublishedAt": 1649285262053,
"lastModified": {
"actor": "urn:li:csUser:7",
"time": 1649285262122
},
"distribution": {
"externalDistributionChannels": [],
"distributedViaFollowFeed": true,
"feedDistribution": "MAIN_FEED"
},
"contentCertificationRecord": "{\"spamRestriction\":{\"classifications\":[],\"contentQualityClassifications\":[],\"systemName\":\"MACHINE_SYNC\",\"lowQuality\":false,\"contentClassificationTrackingId\":\"073BB82AD64A7608E3F142B6D0362E3D\",\"contentRelevanceClassifications\":[],\"spam\":false},\"originCountryCode\":\"ca\",\"modifiedAt\":1649285262024,\"contentHash\":{\"extractedContentMd5Hash\":\"0725A7E31B109EB4CFB84D2648CE3EC8\",\"lastModifiedAt\":1649285262023}}"
}
What am I missing here?? Why is it now showing on LinkedIn??
edit2 : went ahead and tried to share the post again, now all the posts are gone from the company page when viewed as admin, but showing (except the API posts) as a member.... How broken is this API ??????
I will answer my own post. Uploads using CurlFile DO NOT WORK, you have to use Guzzle... Once the upload & publishing are done, the feed will unbreak itself.. The company page will be broken if the endpoint is still waiting for upload while you post.
$client = new \GuzzleHttp\Client();
$res = $client->request('PUT', $__url, [
'headers' => [
'Authorization' => 'Bearer ' . $__token
],
'body' => fopen($__file, 'r')
]
);
if($res){
$res = json_decode($res->getBody());
}

How to fix error 422 on axios post request?

I am trying to populate a already built php database using axios requests, however i keep receiving 422 error and I don't understand what I am missing. Could you please help me :)
This is the error that i get:
xhr.js:177 POST URL/data 422 (Unprocessable Entity)
This is the Post request schema of the DB:
"post": {
"summary": "Post new data row",
"description": "Post new data row",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"data": {
"type": "string",
"example": "{\"test\":1}"
},
"type": {
"type": "string",
"example": "1"
},
"status": {
"type": "integer",
"example": 1
}
},
"required": [
"data",
"type"
]
}
}
}
},
"responses" :{
"422": {
"description": "Error",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"error": {
"type": "string",
"example": "Invalid input"
}
This is my code,
I have several switch cases and they should all work in the same manner:
case "rezervariContact" : {
const {type, titlu, description, phone, email} = this.state;
const contactData = {
type: this.state.type,
data:{
type,
data :{
titlu, description, phone, email
}
},
status:true
}
data = {...contactData};
}
}
await axios({
method: "post",
headers: { "Content-Type": "application/json",
'Accept': '*/*' },
body:data,
url : 'http://xxxxxxxxx.ro/data'
})
.then(function (response) {
console.log("RespResolved::",response.config.params);
})
.catch(function (response) {
console.log("catchErrResp::",response);
});
}
Please if you can spot something let me know.
422 probably means your inputted data is invalid.
The reason for this depends on the server. You could try referring to any documentation for the API/server you are trying to reach.
Check document on http://xxxxxxxxxx.ro/data! It means your post data is valid but server can not hand it correctly!

Neteller paysafe api: Can I create a payment handle without specifying the consumer?

SO, i'm creating a payment handler and I redirect to the given payment_url.
In order to create the payment handler (and get the payment_url), I must specify the consumerId in the request body,
ex createPaymentHandler request:
{
"merchantRefNum": "merchantRefNum-201",
"transactionType": "PAYMENT",
"neteller": {
"consumerId": "netellertest_eur#neteller.com",
},
"paymentType": "NETELLER",
"amount": 500,
"currencyCode": "EUR",
"returnLinks": [{
"rel": "default",
"href": "https://example.com/payment/",
}
]
}
ex createPaymentHandleResponse
{
"id": "82d57742-e2db-48ea-a726-a60e6f8265a3",
"paymentType": "NETELLER",
"paymentHandleToken": "PHQhlWpTRKzBXubN",
"merchantRefNum": "5493aaf1a1d6dd13d2b53412f0ec",
"currencyCode": "USD",
"links": [
{
"rel": "redirect_payment",
"href": "https://customer.at.neteller.com/rest/payment/panel?mid=1090001806&mtid=pay_1090001806_00LwEhZ8WtIy8PmIhRCUi3JScUti6jKi_EUR&amount=0.01&currency=EUR&customerHash=741e624cf6ae4fbca4338cb5597fe531"
}
]
"dupCheck": true,
"status": "INITIATED",
"liveMode": true,
"usage": "SINGLE_USE",
"action": "REDIRECT",
"executionMode": "SYNCHRONOUS",
"amount": 500,
"billingDetails": {
"street": "George Street",
"street2": "3 Edgar Buildings",
"city": "Bath",
"zip": "BA1 2FJ",
"country": "GB"
},
"customerIp": "172.0.0.1",
"timeToLiveSeconds": 899,
"gatewayResponse": {
"orderId": "ORD_0d676b4b-0eb8-4d78-af25-e41ab431e325",
"totalAmount": 3599,
"currency": "EUR",
"status": "pending",
"lang": "en_US",
"processor": "NETELLER"
},
"neteller": {
"consumerId": "johndoe#email.com",
"detail1Description": "description",
"detail1Text": "Details 1 text"
},
"returnLinks": [
{
"rel": "default",
"href": "https://usgaminggambling.com/payment/"
},
{
"rel": "on_completed",
"href": "https://usgaminggambling.com/payment/return/success"
},
{
"rel": "on_failed",
"href": "https://usgaminggambling.com/payment/return/failed"
}
],
"txnTime": "2019-01-24T10:39:50Z",
"updatedTime": "2019-01-24T10:39:50Z",
"statusTime": "2019-01-24T10:39:50Z"
}
When I redirect to the payment_url the email field is already filled with the consumerId ("netellertest_eur#neteller.com") and it's readonly.
The thing is, I should not parse an email, because anyone could login from a different one to their Neteller account.
Is there any other way to get the payment url without parsing the consumerId?
Thanks in advance!
There is a new feature recently added where you can pass consumerIdLocked=false as part of the neteller request object. This will allow edits to the email field once the checkout page renders.
Documentation can be found here: https://developer.paysafe.com/en/additional-documentation/neteller-migration-guide/api/#/introduction/common-objects/meta
{
"merchantRefNum": "merchantRefNum-201",
"transactionType": "PAYMENT",
"neteller": {
"consumerId": "netellertest_eur#neteller.com",
"consumerIdLocked": false
},
"paymentType": "NETELLER",
"amount": 500,
"currencyCode": "EUR",
"returnLinks": [
{
"rel": "default",
"href": "https://example.com/payment/",
}
]
}
consumerId is required and the request will fail, if you don't pass it.
Users usually use the same email as the one in your system or you can create a field for the consumer to enter their email on the deposit page, before the the redirect, in case they would like to use a different one.
I found what I was looking for in the old Neteller REST API.
They have an endpoint for "orders" where you create the order without the consumerId and there is no readonly email in the checkout!

How to get an email address and other info like name and phone together after getting access token LinkedIn signup API with PHP

I am able to gent email using https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~)) and able to get name and profile pic using https://api.linkedin.com/v2/me.My question is that how can i get it together.Is there any single API to call and get all profile info together?
The documentation says something about lite and basic profile permissions but unfortunately there doesn't seem to be a way to get both in one query.
Profile Json Response:
{
"firstName":{
"localized":{
"en_US":"Bob"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"localizedFirstName": "Bob",
"headline":{
"localized":{
"en_US":"API Enthusiast at LinkedIn"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"localizedHeadline": "API Enthusiast at LinkedIn",
"vanityName": "bsmith",
"id":"yrZCpj2Z12",
"lastName":{
"localized":{
"en_US":"Smith"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"localizedLastName": "Smith",
"profilePicture": {
"displayImage": "urn:li:digitalmediaAsset:C4D00AAAAbBCDEFGhiJ"
}
}
Contact Json Response:
{
"elements": [
{
"handle": "urn:li:emailAddress:3775708763",
"handle~": {
"emailAddress": "ding_wei_stub#example.com"
},
"primary": true,
"type": "EMAIL"
},
{
"handle": "urn:li:phoneNumber:6146249836070047744",
"handle~": {
"phoneNumber": {
"number": "158****1473"
}
},
"primary": true,
"type": "PHONE"
}
]
}
The reason might be that there are separated APIs, Contact API and Profile API.

[Dialogflow]Update Permission through Webhook format (for push notifications)

ORIGINAL REQUEST: I'm trying to implement the push notifications following the documentation: https://developers.google.com/actions/assistant/updates/notifications
I'm using Dialogflow with webhooks (in PHP) and the documentation is giving example in nodeJS
Right now, i'm blocked because of the Update permission, here's my Webhook response :
{
"source": "webhook",
"payload": {
"google": {
"expectUserResponse": true,
"systemIntent": {
"intent": "actions.intent.PERMISSION",
"data": {
"#type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
"permissions": [
"UPDATE"
]
},
"updatePermission": {
"intent": "notification.simple.text"
}
}
}
}
}
When I do the simulation, asks me a permission for a push, but not for the intent I specified.
I'm quiet sure that the problem is the updatePermission, something must be wrong with that:
Is it the field name?
In intent, i put the intent name that i filled in dialogflow, maybe do i have to an use action? Is it in the good format ?
If someone can help me or just give me an example of a clean response for an update permission.
Thanks!
Solution
I just found why, my json wasn't good, the updatePermissionValueSpec must be into data object.
{
"source": "webhook",
"payload": {
"google": {
"expectUserResponse": true,
"systemIntent": {
"intent": "actions.intent.PERMISSION",
"data": {
"#type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
"permissions": [
"UPDATE"
],
"updatePermissionValueSpec": {
"intent": "notification_simple_text"
}
}
}
}
}
}
I believe updatePermission should be named updatePermissionValueSpec.
Example response:
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "PLACEHOLDER"
}
}
]
},
"systemIntent": {
"intent": "actions.intent.PERMISSION",
"data": {
"#type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
"permissions": [
"UPDATE"
],
"updatePermissionValueSpec": {
"intent": "intent_name"
}
}
}
}
}

Categories