How to use the REST API to Update Provider Config? - cluedin

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": ""
}
}

Related

to generate body contents as --data-raw from httpsnippet

I am trying to generate raw body from the
const snippet = new HTTPSnippet({
method: 'POST',
url: 'http://mockbin.com/request',
headers: [{
name: 'content-type',
value: 'Application/json',
}],
queryString: [
{
"name": "param1",
"value": "value1",
"comment": ""
},
{
"name": "param1",
"value": "value1",
"comment": ""
}
],
postData: {
"mimeType": "application/x-www-form-urlencoded",
"params": [{
"name": "body1",
"value": "sds",
"comment": ""
}],
"text" : "plain posted data",
"comment": "",
}
});
snippet.convert('shell', 'curl');
but just the value of text plain posted data is being printed in the body (postman).
but i am expecting the body as
{
"body1": "sds"
}
also I noticed it generate curl as --data 'plain posted data' but it should be like
--data-raw '{ "body1": "sds" }'

Gitlab Group API returns different values depending on the token used

I am querying Gitlab group API using curl. The result I get when I use my PAT token is different than when I use the CI_JOB_TOKEN. The PAT token returns all the groups I have access to but using the CI_JOB_TOKEN returns a weird response. I read the CI_JOB_TOKEN has the same permission as the user running the pipeline.
'curl --header "--header "JOB-TOKEN: $CI_JOB_TOKEN" https://gitlab.com/api/v4/groups"'
Returns the below response which I have no idea what it is. It is not one of my groups:
teur-territoires/france-relance/","visibility":"public","share_with_group_lock":false,"require_two_factor_authentication":false,"two_factor_grace_period":48,"project_creation_level":"developer","auto_devops_enabled":null,"subgroup_creation_level":"maintainer","emails_disabled":null,"mentions_disabled":null,"lfs_enabled":true,"default_branch_protection":2,"avatar_url":"https://gitlab.com/uploads/-/system/group/avatar/16026247/france-relance-vert.png","request_access_enabled":true,"full_name":"🇫🇷 France Relance","full_path":"france-relance","created_at":"2022-02-05T20:55:13.007Z","parent_id":null,"ldap_cn":null,"ldap_access":null}]
While running with my PAT token, it returns the right results and in the right format:
curl --silent --header "PRIVATE-TOKEN: $MY_PAT_TOKEN" "https://gitlab.com/api/v4/groups"
[
{
"id": xxxxxx,
"web_url": "https://gitlab.com/groups/txxxxest",
"name": "xxxx",
"path": "xxxxx",
"description": "",
"visibility": "private",
"share_with_group_lock": false,
"require_two_factor_authentication": false,
"two_factor_grace_period": 48,
"project_creation_level": "developer",
"auto_devops_enabled": null,
"subgroup_creation_level": "maintainer",
"emails_disabled": null,
"mentions_disabled": null,
"lfs_enabled": true,
"default_branch_protection": 2,
"avatar_url": null,
"request_access_enabled": true,
"full_name": "xxxx",
"full_path": "xxxxx",
"created_at": "2023-01-29T08:41:38.696Z",
"parent_id": null,
"ldap_cn": null,
"ldap_access": null,
"marked_for_deletion_on": null
},
{
"id": xxxxxx,
"web_url": "https://gitlab.com/groups/xxxx",
"name": "xxx",
"path": "xxx",
"description": "",
"visibility": "private",
"share_with_group_lock": false,
"require_two_factor_authentication": false,
"two_factor_grace_period": 48,
"project_creation_level": "developer",
"auto_devops_enabled": null,
"subgroup_creation_level": "maintainer",
"emails_disabled": null,
"mentions_disabled": null,
"lfs_enabled": true,
"default_branch_protection": 2,
"avatar_url": null,
"request_access_enabled": true,
"full_name": "xxxxxn",
"full_path": "xxxxxx",
"created_at": "2023-01-29T13:58:49.800Z",
"parent_id": null,
"ldap_cn": null,
"ldap_access": null
}
I am not sure why it is exhibiting this behaviour. I dont want to manage a PAT token if I can use the CI_JOB_TOKEN
There is a typo in your CI script
'curl --header "--header "JOB-TOKEN: $CI_JOB_TOKEN" https://gitlab.com/api/v4/groups"'
it should be:
'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" https://gitlab.com/api/v4/groups"'

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.

Box Api - How to Get user details who commented a file

I have a scenario in Box of commenting a file using Box Api. I have used Box api to add a comment. When displaying all the comments, it shows commented person name same for all comments.
How should I add a comment to differentiate who has commented it using Box API
Sample comment List:
{
"type": "comment",
"id": "1111",
"is_reply_comment": false,
"message": "Sample Comment 1",
"created_by": {
"type": "user",
"id": "111",
"name": "AAA",
"login": "aaa#aaa.com"
},
"created_at": "2016-08-11T00:01:56-07:00",
"item": {
"id": "78110824178",
"type": "file"
},
"modified_at": "2016-08-11T00:01:56-07:00"
}
{
"type": "comment",
"id": "2222",
"is_reply_comment": false,
"message": "Sample Comment 2",
"created_by": {
"type": "user",
"id": "111",
"name": "AAA",
"login": "aaa#aaa.com"
},
"created_at": "2016-08-11T00:01:56-07:00",
"item": {
"id": "78110824178",
"type": "file"
},
"modified_at": "2016-08-11T00:01:56-07:00"
}
Please help to add comments for different users
To comment as a specific user, you can use the As-User header. Here is an example:
curl https://api.box.com/2.0/comments \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "As-User: USER_ID" \
-d '{"item": {"type": "file", "id": "FILE_ID"}, "message": "YOUR_MESSAGE"}' \
-X POST

buddy-http-api response Unauthorized

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 !

Resources