buddy-http-api response Unauthorized - node.js

Hello Stackoverflower,
I'm setting up buddy-http-api using docker.
After docker container launch is done, I ssh to docker container for testing API.
I run:
curl http://localhost:9123/api/account -X POST -H "Content-Type: application/json" \
-H "Accept: application/json" \
-d "{ \
\"username\": \"user2#ab.com\", \
\"password\": \"12345678\", \
\"email\": \"thanh.nguyen2891#gmail.com\"\
}"
I got:
Unauthorized
I'm not sure how to put it into authenticate. I have read http://buddycloud.com/api#create-post
logs:
{
"req": {
"url": "/api/account",
"headers": {
"user-agent": "curl/7.35.0",
"host": "localhost:9123",
"accept": "*/*",
"content-type": "application/json; charset=utf-8",
"content-length": "45"
},
"method": "POST",
"httpVersion": "1.1",
"originalUrl": "/api/account",
"query": {}
},
"res": {
"statusCode": 401
},
"responseTime": 1,
"level": "info",
"message": "HTTP POST /api/account"
}
Thanks in advance !

Related

How to use the REST API to Update Provider Config?

While trying to use the CluedIn REST API command to update provider configuration details the response is the html code for the CluedIn webpage (error) without any details as to why. When checking the values which should be updated, they are not.
What is the correct process to update provider configuration variables via the REST API?
If you work with CluedIn 3.2.4, you can update the integration configuration from the "Authentication" tab:
If you are on earlier 3.x versions, you have to do two steps: get the provider configuration, and update the provider configuration.
Before you start, please get an authentication token:
curl --location --request POST
'https://orgname.domain/auth/connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=admin#domain' \
--data-urlencode 'password=yourstrongpassword' \
--data-urlencode 'client_id=int' \
--data-urlencode 'grant_type=password'
Example response:
{
"access_token": "...",
"expires_in": 3600,
"token_type": "Bearer",
"refresh_token": "...",
"scope": "offline_access openid profile ServerApiForUI SpecificBlobApi"
}
Now, get the provider configuration.
First, you need the configuration ID. That's the last part of the URL when you open the configured integration in the browser. I.e. https://orgname.domain/admin/configuration/integration-guid/youneed-this-guid.
Now run:
curl --location --request GET 'https://orgname.domain/api/api/configuration/providers?id=your-integration-configuration-guid' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer your-auth-token'
Expected response:
{
"ProviderId": "...",
"Name": "...",
"Guide": null,
"PlanLevel": 1,
"Configuration": {
"Authorization": "...",
"firstTime": false,
"LastCrawlFinishTime": "2021-10-27T08:38:51.9620662+00:00",
"lastCursor": {}
},
"Active": true,
"OrganizationId": "...",
"Type": "Cloud",
"helperConfiguration": {
"ClientId": "...",
"ClientSecret": "..."
},
"CodeName": "...",
"UserId": "...",
"SourceQuality": 5,
"Source": "",
"AutoSync": false,
"AuthType": null,
"Id": "...",
"UserName": "admin#domain",
"AuthTypes": null,
"AccountId": "",
"AccountDisplay": "Integration Name",
"EntityId": "...",
"SupportsConfiguration": true,
"SupportsWebhooks": false,
"SupportsAutomaticWebhookCreation": true,
"FailingAuthentication": false,
"Stats": {
"Name": "Provider Stats",
"ProviderStatus": {
"Crawling": {
"$type": "CluedIn.Server.WebApi.Models.Providers.ProviderStatusCrawlInfo, CluedIn.Server.WebApi",
"TaskCount": 0,
"TasksCompletedCount": 0,
"TasksCompletedPerMinute": 0.0,
"TasksFailedCount": 0,
"TasksQueuedCount": 0,
"ExpectedTasksCount": 0
},
"Processing": null,
"State": "Crawling",
"Summary": null
},
"ProviderId": "...",
"ConfigurationId": "...",
"OrganizationId": "..."
},
"Status": {
"NextExecution": "2021-10-27T12:38:00Z"
},
"WebhookManagementEndpoints": null,
"Webhooks": null,
"DataStatistics": {
"EntityTypeStatistics": []
},
"ExpectedData": 0,
"ExpectedStatistics": null,
"ExpectedTaskCount": 0,
"ExpectedTime": "00:00:00",
"CreatedDate": "2021-07-28T08:37:50.7865925+00:00"
}
In this response, change the helperConfiguration and Put it back in a response body:
curl --location --request PUT 'https://orgname.domain/api/api/v2/organization/Providers?accountId=&providerId=your-configuration-guid' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer your-access-token' \
--data-raw 'your-updated-json'
Expected response:
{
"AccountDisplay": "...",
"AutoSync": false,
"Source": "",
"SourceQuality": 5,
"Id": "...",
"appUrl": "",
"SupportsWebHooks": false,
"SupportsAutomaticWebhookCreation": true,
"SupportsConfiguration": true,
"helperConfiguration": {
"ClientId": "...",
"ClientSecret": "...",
"Authorization": "...",
"firstTime": false,
"LastCrawlFinishTime": "01/01/0001 00:00:00 +00:00",
"lastCursor": ""
},
"configurationDictionary": {
"ClientId": "...",
"ClientSecret": "...",
"Authorization": "...",
"firstTime": false,
"LastCrawlFinishTime": "01/01/0001 00:00:00 +00:00",
"lastCursor": ""
}
}

New Relic: Script always returns Status 400 but works in Postman

I'm trying to make a healthcheck for my service in New Relic. So I just want to call one of my APIs every x minutes and see if it returns 200.
In New Relic I created a new synthetic monitor and now I'm trying to write a script for that monitor.
The script is supposed to make a post request to our service and receive a token in the response with status 200. In Postman this post request works and returns the token + Status 200 (I replaced the sensitive strings with <...>):
curl --location --request POST <TOKEN_URL> \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=<CLIENT_ID_DEV>' \
--data-urlencode 'client_secret=<CLIENT_SECRET_DEV>'
But when I try to recreate that with the script, it always returns Status 400 Bad Request.
This is my script:
var assert = require('assert');
//Defining my authentication credentials.
var IDK_TOKEN_URL = $secure.TOKEN_URL;
var CLIENT_ID = $secure.CLIENT_ID_DEV;
var CLIENT_SECRET = $secure.CLIENT_SECRET_DEV;
var options = {
url: IDK_TOKEN_URL,
body: JSON.stringify({
grant_type: 'client_credentials',
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
};
//Define expected results using callback function.
function callback(error, response, body) {
console.log(response.statusCode + " status code")
assert.ok(response.statusCode == 200, 'Expected 200 OK response');
var info = JSON.parse(body);
assert.ok(info.success == true, 'Expected True results in Response Body, result was ' + info.success);
console.log("End reached");
}
//Make POST request, passing in options and callback.
$http.post(options, callback);
This is what I see in the console:
It seems to automatically append a port 443 to my url, so instead of <my url>.io/oidc/v1/token, the request seems to get fired to <my url>.io:443/oidc/v1/token?
And when I click on "View resource" in the image above, I see:
But I'm using a post method, why is it saying anything about get method is not allowed?
This is the HAR log that I can download in the new relic console:
"request": {
"cookies": [],
"headers": [
{
"name": "Content-Type",
"value": "application/x-www-form-urlencoded"
},
{
"name": "host",
"value": "<my url>.io"
},
{
"name": "content-length",
"value": "187"
},
{
"name": "X-Abuse-Info",
"value": "Request sent by a New Relic Synthetics Monitor (https://docs.newrelic.com/docs/synthetics/new-relic-synthetics/administration/identify-synthetics-requests-your-app) - monitor id: df1817f0-fac2-49f4-a0d5-479d254dfa1a | account id: 2807718"
},
{
"name": "X-NewRelic-Synthetics",
"value": "[1,2807718,\"fddc843c-8fe0-497f-bf5b-52c2805a265e\",\"b6da79b9-37ab-4a8a-a792-f3fa0f99f205\",\"df1817f0-fac2-49f4-a0d5-479d254dfa1a\"]"
}
],
"headersSize": 607,
"bodySize": 187,
"method": "POST",
"url": "<my url>.io:443/oidc/v1/token/",
"httpVersion": "HTTP/1.1",
"queryString": [],
"postData": {
"mimeType": "application/x-www-form-urlencoded",
"text": "{\"grant_type\":\"client_credentials\",\"client_id\":\"_SECURECREDENTIAL_\",\"client_secret\":\"_SECURECREDENTIAL_\"}",
"params": []
},
"_ajax": false,
"_mixedContentType": "unknown",
"_referrerPolicy": "",
"_isLinkPreload": false,
"_host": "<my url>.io",
"_port": 443,
"_path": "/oidc/v1/token/"
},
"response": {
"cookies": [],
"headers": [
{
"name": "Date",
"value": "Thu, 06 May 2021 10:21:05 GMT"
},
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "Content-Length",
"value": "67"
},
{
"name": "Connection",
"value": "close"
},
{
"name": "Cache-Control",
"value": "no-cache, no-store, max-age=0, must-revalidate"
},
{
"name": "Expires",
"value": "0"
},
{
"name": "Pragma",
"value": "no-cache"
},
{
"name": "Referrer-Policy",
"value": "origin"
},
{
"name": "Strict-Transport-Security",
"value": "max-age=31536000 ; includeSubDomains"
},
{
"name": "Vary",
"value": "accept-encoding,origin,access-control-request-headers,access-control-request-method,accept-encoding"
},
{
"name": "X-Content-Type-Options",
"value": "nosniff"
},
{
"name": "X-Frame-Options",
"value": "DENY"
},
{
"name": "X-Vcap-Request-Id",
"value": "e2006a3c-0c27-4194-6b81-d9f037158ca3"
},
{
"name": "X-Xss-Protection",
"value": "1; mode=block"
}
],
"headersSize": 544,
"bodySize": 67,
"status": 400,
"statusText": "Bad Request",
"httpVersion": "HTTP/1.1",
"content": {
"size": 639,
"compression": 572,
"mimeType": "application/json",
"text": ""
},
"redirectURL": "",
"_chromeStatusText": "Bad Request",
"_connectionReused": false,
"_fromServiceWorker": false,
"_fromDiskCache": false,
"_fromAppCache": false,
"_fromCache": false
},
I had to replace 'body' with 'form' like in this example.
I aslo added now the call to the API after the token was received. The final script was:
var assert = require('assert');
//Define your authentication credentials.
var TOKEN_URL = $secure.TOKEN_URL;
var MY_SERVICE_BASE_URL = $secure.MY_SERVICE_BASE_URL_DEV;
var CLIENT_ID = $secure.CLIENT_ID_DEV;
var CLIENT_SECRET = $secure.CLIENT_SECRET_DEV;
function new_relic_callback(err, response, body) {
assert.equal(response.statusCode, 200, 'Expected a 200 OK response');
};
function api_request_callback(err, response, body) {
var parsed_body = JSON.parse(body);
var api_request = {
url: CONSENT_BASE_URL + '/rest of URL...',
headers: {
'Authorization': 'Bearer ' + parsed_body["access_token"]
}
};
$http.get(api_request, new_relic_callback);
};
var token_request = {
url: TOKEN_URL,
form: {
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
grant_type: "client_credentials"
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
};
$http.post(token_request, api_request_callback);

Creating a user via Microsoft Graph API

I am trying to perform this curl request
curl --location --request POST 'https://graph.microsoft.com/v1.0/users' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {BEARER_TOKEN}' \
--data-raw '{
"accountEnabled": true,
"displayName": "displayName-value",
"mailNickname": "mailNickname-value",
"userPrincipalName": "test666#mytennant.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": true,
"password": "password"
}
}'
I keep getting
{
"error": {
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation.",
"innerError": {
"date": "2020-10-23T14:01:06",
"request-id": "caf9e0be-88fc-4a4e-a6eb-fed1ccedb90c",
"client-request-id": "caf9e0be-88fc-4a4e-a6eb-fed1ccedb90c"
}
}
}
I have the following permissions set on the app registration
Can someone please help me figure out what's wrong here?
Based on the error you are provided it seems to be you are not having right permission to create the user.
In the token, you are missing the permissions, so before making the graph request you need to have the token with
User.ReadWrite.All, Directory.ReadWrite.All.
I made the below request, without having the required permission then I received the same error as you can see below
Then later I added the permissions and requested for the new token, then made the graph call. Now I was successfully able to create the user
Curl
curl --location --request POST 'https://graph.microsoft.com/v1.0/users' \
--header 'Authorization: Bearer token' \
--header 'Content-Type: application/json' \
--data-raw '{​​​​ "accountEnabled": true, "displayName": "displayName-value", "mailNickname": "mailNickname-value", "userPrincipalName": "upn-value1#xx.live", "passwordProfile" : {​​​​ "forceChangePasswordNextSignIn": true, "password": "xx#123" }​​​​ }​​​​'

API call made using requests in Python 3 returns HTML not JSON

I'm using Python 3.7 and requests 2.21.0 to integrate payment gateway.
I have the following example form sandbox which works as expected (returns JSON):
curl -X POST https://secure.snd.payu.com/api/v2_1/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer d9a4536e-62ba-4f60-8017-6053211d3f47" \
-d '{
"notifyUrl": "https://your.eshop.com/notify",
"customerIp": "127.0.0.1",
"merchantPosId": "300746",
"description": "RTV market",
"currencyCode": "PLN",
"totalAmount": "21000",
"buyer": {
"email": "john.doe#example.com",
"phone": "654111654",
"firstName": "John",
"lastName": "Doe",
"language": "pl"
},
"settings":{
"invoiceDisabled":"true"
},
"products": [
{
"name": "Wireless Mouse for Laptop",
"unitPrice": "15000",
"quantity": "1"
},
{
"name": "HDMI cable",
"unitPrice": "6000",
"quantity": "1"
}
]
}'
On the other hand, I have the following Python code
import requests
import json
url = "https://secure.snd.payu.com/api/v2_1/orders"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer d9a4536e-62ba-4f60-8017-6053211d3f47"
}
data = {
"notifyUrl": "https://your.eshop.com/notify",
"customerIp": "127.0.0.1",
"merchantPosId": "300746",
"description": "RTV market",
"currencyCode": "PLN",
"totalAmount": "21000",
"buyer": {
"email": "john.doe#example.com",
"phone": "654111654",
"firstName": "John",
"lastName": "Doe",
"language": "pl"
},
"settings":{
"invoiceDisabled":"true"
},
"products": [
{
"name": "Wireless Mouse for Laptop",
"unitPrice": "15000",
"quantity": "1"
},
{
"name": "HDMI cable",
"unitPrice": "6000",
"quantity": "1"
}
]
}
response = requests.post(url, data=json.dumps(data), headers=headers)
However, instead of JSON response, I'm getting HTML. Any ideas why? When using Python 2.7 I've used urllib and it worked but using urllib to make a call in Python 3.7 produces exactly the same effect, that is HTML instead of JSON.
Response should look like
{
"status":{
"statusCode":"SUCCESS",
},
"redirectUri":"{payment_summary_redirection_url}",
"orderId":"WZHF5FFDRJ140731GUEST000P01",
"extOrderId":"{YOUR_EXT_ORDER_ID}",
}
It was enough to add allow_redirects=False.

Google Street View Publish return's "Photo does not have upload reference." after statusCode 200

I'm using NodeJS to upload panoramic images.
When I make #2 informed in the Google documentation, I get the following return:
Request
{
"url": "UPLOAD_URL",
"body": "/PATH_TO_PANO/pano.jpg",
"method": "POST",
"headers": {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "image/jpeg"
}
}
Response
{
"statusCode": 200,
"body": "",
"headers": {
"x-guploader-uploadid": "AEnB2UoJt4gvmmU6gXZvWDRu4b0DUCeT5vuPKLGcZqM4Tzo9HssCLoloTgAACRmxmP0U5DDYvHXpThCjRslW80bEKLZjUjJB3QNZ5w- j0jd8jdtVnH8X0c",
"content-length": "0",
"date": "Tue, 26 Sep 2017 21:05:17 GMT",
"server": "UploadServer",
"content-type": "text/html; charset=UTF-8",
"alt-svc": "quic=\":443\"; ma=2592000; v=\"39,38,37,35\"",
"connection": "close"
},
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "streetviewpublish.googleapis.com",
"port": 443,
"hostname": "streetviewpublish.googleapis.com",
"hash": null,
"search": null,
"query": null,
"pathname": "/media/user/USER_ID/photo/PHOTO_ID",
"path": "/media/user/USER_ID/photo/PHOTO_ID",
"href": "https://streetviewpublish.googleapis.com/media/user/USER_ID/photo/PHOTO_ID"
},
"method": "POST",
"headers": {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "image/jpeg",
"content-length": 45
}
}
}
But when I upload the metadata of the photo, I get the following message:
Request
{
"url": "https://streetviewpublish.googleapis.com/v1/photo?key=YOUR_API_KEY",
"method": "POST",
"headers": {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
"Content-Length": 9385487
},
"data": {
"uploadReference": {
"uploadUrl": "UPLOAD_URL"
},
"pose": {
"heading": 110,
"latLngPair": {
"latitude": -29.937386,
"longitude": -60.996952
}
},
"captureTime": {
"seconds": 1506448064836
}
}
}
Response
{
"error": {
"code": 400,
"message": "Photo does not have upload reference.",
"status": "INVALID_ARGUMENT"
}
}
There are not many references to basing myself and finding the problem. For that reason I would like the help of someone who may have gone through something similar.
I have replicated your issue. I've encountered this error when I didn't specify the UPLOAD_URL in the request.
{
"error": {
"code": 400,
"message": "Photo upload url does not match required format.",
"status": "INVALID_ARGUMENT",
"details": [
{
...
}
]
}
}
Make sure that you have added the UPLOAD_URL in the request. Check this documentation for more information.

Resources