Auth0 API - create user - phone_number madness - auth0

It’s not easy to understand this API … phone number field …
The documentation says it's optional
phone_number string (optional)
The user’s phone number (following the E.164 recommendation), only valid for users from SMS connections.
my tries:
#1 request
{
"email": "adriana.will#yahoo.com",
"phone_number": "",
...
"connection": "Username-Password-Authentication",
...
}
Response
Payload validation error: 'String does not match pattern ^\\+[0-9]{1,15}$: ' on property phone_number (The user's phone number (following the E.164 recommendation), only valid for users from SMS connections).
#2 request (without phone_number)
{
"email": "adriana.will#yahoo.com",
"connection": "Username-Password-Authentication",
...
}
Response
Payload validation error: 'Expected type string but found type null' on property phone_number (The user's phone number (following the E.164 recommendation), only valid for users from SMS connections)
#3 request
{
"email": "adriana.will#yahoo.com",
"phone_number": "+113407178302",
...
"connection": "Username-Password-Authentication",
...
}
Response
phone_number is not allowed
Anyone please ? What should I put ?

this does the magic
{
"email":"test#test.com",
"connection":"Username-Password-Authentication",
"password":"password"
}

Related

insert multiple rows in a data extension by using rest api

I'm trying to insert multiple rows in my data extension by using a POST request on postman. I'm using this documentation :https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/postDataExtensionRowsetByKey.html.
Details of my first POST request :
My URL :
https://MY_SUBDOMAIN.auth.marketingcloudapis.com/v2/token
My body (by using the informations of the package created on marketing cloud) :
{
"client_id": "ssd6ssd6ssd6ssd6ssd6ss",
"client_secret": "p3sp3sp3sp3sp3sp3sp3sp3",
"account_id": "7842222",
"grant_type": "client_credentials"
}
I send the request => Status 200 OK
I copy the tokken access.
I create a second POST request.
Tab Authorization, Type = Bearer Token, I paste my token access
Details of my second POST request :
My URL :
https://MY_SUBDOMAIN.rest.marketingcloudapis.com/hub/v1/dataevents/key:EXTERNAL_KEY_OF_MY_DATA_EXTENSION/rowset
My body :
`
Host: https://MY_SUBDOMAIN.rest.marketingcloudapis.com
POST /hub/v1/dataevents/EXTERNAL_KEY_OF_MY_DATA_EXTENSION/rowset
Content-Type: application/json
[
{
"keys":{
"ID_Crawl": "test123"
},
"values":{
"Source": "2013-05-23T14:32:00Z",
"Type_contenu": "no",
"Statut_Notification": "non lu",
"Champ": "20081105",
"Origine_contenus": "test blablablablablablabla",
"Date_crawl": 02/02/2023
}
},
{
"keys":{
"ID_Crawl": "test"
},
"values":{
"Source": "2013-05-23T14:32:00Z",
"Type_contenu": "ok",
"Statut_Notification": "valide",
"Champ": "00000007",
"Origine_contenus": "test blablablablablablabla",
"Date_crawl": "02/02/2023"
}
}
]
I send the request and I had an error message (Status:400 Bad request means that bad synthax):
{"documentation":"https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/error-handling.htm","errorcode":0,"message":"Bad Request"}
Does someone know where is my mistake ?
Sorry if it seems that my mistake is a stupid one, I'm completely a beginner in api call

Way to detect invalid device token in FCM HTTP v1 API

we are using FCM HTTP v1 API to send push notification.
When, our users register their device tokens, our push server just stores it to database without verification because FCM does not provide token verification APIs.
The only time the push server could detect whether the device token is valid or not is when sending push notification via FCM.
According to FCM registration token management, if the device token is invalid the FCM server responds with UNREGISTERED or INVALID_ARGUMENT.
However, the INVALID_ARGUMENT code can be returned when using invalid payload as well. So we can not distinguish errors between invalid device token and invalid payload.
The following is actual response from the FCM server in case of using invalid device token and invalid payload respectively.
{
"error": {
"code": 400,
"message": "The registration token is not a valid FCM registration token",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode": "INVALID_ARGUMENT"
}
]
}
}
HTTP/1.1 400 Bad Request
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"priority\" at 'message': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "message",
"description": "Invalid JSON payload received. Unknown name \"priority\" at 'message': Cannot find field."
}
]
}
]
}
}
When the token has a proper format but its user is no longer active, you will receive an UNREGISTERED response indicating that you should delete that token from your backend.
However, if you send a token that does not have a valid format (it has been modified in your backend or truncated, for instance) you will receive an INVALID_ARGUMENT. If this is the case you probably want to check your code because you may be modifying the token somewhere (in App or backend). Probably you have to manually detect and delete those tokens.
Once this is solved, you do not have to worry anymore about the INVALID_ARGUMENT response to delete the tokens, except if you make further changes that corrupt them again.

Strapi API register returning a 400 error

I’ve been creating a web app with a login and a registration function and so far everything has been going great. I managed to connect the app to the api/auth/local api endpoint and send some nice post requests.
Now, I’ve been trying to send requests to the http://localhost:1337/api/auth/local/register endpoint and without any success. I’ve been doing this according to:
https://docs.strapi.io/developer-docs/latest/plugins/users-permissions.html#registration
I keep getting a 400 error:
{
"data": null,
"error": {
"status": 400,
"name": "ApplicationError",
"message": "An error occurred during account creation",
"details": {
}
}
}
If I try to send a request with an email that’s already registered in strapi, the response will give me the correct error:
{
"data": null,
"error": {
"status": 400,
"name": "ApplicationError",
"message": "Email is already taken",
"details": {
}
}
}
In the public and authenticated user roles, I’ve allowed every single one of them, for now.
Enable confirmation emails are set to false.
Email confirmation
Public user permission
For the headers, I’m using Content-type : application/json
the raw json body I'm posting:
{
"email": "manager1#strapi.io",
"password": "testtest1",
"username": "manager1"
}
This is my first project with strapi and so far it went pretty well. I’m not sure if I’m missing out on something or if I’m doing something else wrong.
Any help is appreciated!
I figured it out, it wasn’t as complicated as I expected.
In the user I had different fields, like firstName, lastName etc. All of these fields were required.
I made the fields not required, and now it works.

Resolve Discord-Tag get Discord-ID programmatically

I want to add a function to my userprofiles where users can enter their discord tag and if they do so, I want to resolve this to a link to their discordprofile so that users only have to click on the discordtag to open the profile in discord.
For that I need the ID. What Request do I need to send to the discord api in order to get the user ID for the entered tag?
After some experiments with discord friend sending. I found out that you can actually obtain user the user ID by sending friend request.
Here's how:
Make a add request friend request to example#1234
Make another request to the relationship(AKA friend) list to get all pending "friends" with ID, username, avatar... This list actually contains all of the actual friends from the person that sent a friend request.
To find the requested username in the friend list, all you need is a loop searching for the corresponding username + discriminator.
Output the ID(if that's what you wanted), after the username and discriminator match.
Delete the pending request.
Here's a python script I wrote that will output the ID of the user with inputs of username, discriminator, and an user token(used for sending an authorized friend request):
import requests
import json
# inputs
username = 'asdf'
discriminator = '1234'
TOKEN = 'ONLY USER TOKEN'
url = 'https://discord.com/api/v8/users/#me/relationships'
headers = {
"authorization": TOKEN
}
# setting up a payload for sending friend request.
payload = {
'username': username,
'discriminator': discriminator
}
requests.post(url, json=payload, headers=headers) # step 1
result = requests.get(url, headers=headers).json() # step 2
if hasattr(result, 'message'):
print('Invalid user token')
else:
user_id = None
for client in result: # step 3: a loop for finding the the username in the friend list
if f'{client["user"]["username"]}#{client["user"]["discriminator"]}' == f'{username}#{discriminator}':
user_id = client['id'] # step 4: save the user ID after finding it in the friend list
break
if user_id is None: # if no match is found then the user with that username and discriminator does not exist.
print('user not found')
else:
url = f'https://discord.com/api/v8/users/#me/relationships/{user_id}'
requests.delete(url, headers=headers) # step 5: delete the pending request
print(user_id) # print out the user ID
And here's the data structure of the requested json from step 2:
[
{
"id": "12345678901",
"type": 1,
"nickname": null,
"user": {
"id": "12345678901",
"username": "example1",
"avatar": "1234567890abcdef",
"discriminator": "1234",
"public_flags": 123
}
},
{
"id": "12345678902",
"type": 1,
"nickname": null,
"user": {
"id": "12345678902",
"username": "example2",
"avatar": "1234567890abcdef",
"discriminator": "1234",
"public_flags": 123
}
},
{
"id": "12345678903",
"type": 1,
"nickname": null,
"user": {
"id": "12345678903",
"username": "example3",
"avatar": "1234567890abcdef",
"discriminator": "1234",
"public_flags": 123
}
}
]
Downside:
You have to use an user token for sending the friend request.
Updates:
10/4/2020: Added in error detection for invalid token and invalid username.

Create MasterCard tokenization API

I have a mobile app containing payment method via MasterCard. I have this tutorial:
https://ap-gateway.mastercard.com/api/documentation/apiDocumentation/rest-json/version/latest/api.html?locale=en_US
I want to create Tokenization which contains customer's master detail, I have followed this tutorial part:
https://ap-gateway.mastercard.com/api/documentation/apiDocumentation/rest-json/version/latest/operation/Tokenization%3a Create or Update Token (with system-generated token).html?locale=en_US
I tried with :
POST https://ap-gateway.mastercard.com/api/rest/version/41/merchant/{{MyMerchantID}}/token
Params:
{
"sourceOfFunds": {
"type": "CARD",
"provided": {
"card":{
"number": "5123450000000008",
"expiry": {
"month": "05",
"year": "17"
}
}
}
Note: The number is a mastercard test number.
I am always get this error:
error
cause "INVALID_REQUEST"
explanation "Invalid credentials."
result "ERROR"
I followed the params in second URL.
Can anyone help? Are the params correct or I missed something?
In your configuration file, you need to set the following:
$configArray["merchantId"] = "[merchantId]";
// API username in the format below where Merchant ID is the same as above
$configArray["apiUsername"] = "merchant.[merchantId]";
// API password which can be configured in Merchant Administration
$configArray["password"] = "your api password";
Setting the above parameters in the config file will solve your problem
Try replacing "ap-gateway" with the real gateway provided for you. Your merchantID is not supported in test gateway.
First, you should ask you bank to enable the tokenization for your merchant account
POST
https://ap-gateway.mastercard.com/api/rest/version/61/merchant/{{MyMerchantID}}/token
you have to set Authorization->Basic Auth
Username : Your_MerchantID
Password : ApiPassword
Params:
{
"session": {
"id": "SESSION0002510583427E2239608H32"
}
}