Can't create webhook through v2 api endpoint - smooch

I am trying to dispatch webhook create endpoint and getting 403 Forbidden response code with no error information in body. My request looks like:
POST /v2/apps/618ce23498488b00e1582723/integrations/618ce235a6ccf400e1a4b992/webhooks HTTP/1.1
Host: api.smooch.io
Content-Type: application/json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6ImFwcF82MThjZTIzNGZiYTk5MDAwZTFiZDgyYWMifQ.eyJzY29wZSI6ImFwcCJ9.hXigeREGoUQ8YtM_gPUXfgWEGumbnlbBNLk_*******
Content-Length: 120
{
"target": "https://example.com/inbound-smooch-request",
"triggers": [
"conversation:message"
]
}
Response I am getting:
{"errors":[{"code":"forbidden","title":"Forbidden"}]}
That's how I generate Bearer token:
$signer = new Sha256();
$a = (new Builder())
->withHeader('alg', 'HS256')
->withHeader('typ', 'JWT')
->withHeader('kid', 'app_618ce234fba99000e1bd8***')
->withClaim('scope', 'app')
->getToken($signer, new Key('4K5KoVqLixLOUrkJSebr4rFsvZAu66d2WD8WEhXDgAZnJaltEpnHWpF_PUwQUGuNlFnBXvr8mtGsvNKj******'));
echo $a . PHP_EOL;
die();
Webhook api documentation: https://docs.smooch.io/rest/#operation/createWebhook
There is a bearerAuth (integration, app) explanation but there is no information what does this means. Documentation says that there are only two scopes: account and app. So what is this?
Other endpoints work normally (app create, app keys create, integration create)
Tried Basic auth also but it did not help.

The *Webhook endpoints are used (in v2) to create/update/remove webhooks from an existing customIntegration (integration with type: custom).
This endpoint will allow you to create a new integration, and when you set type: custom, it will also accept a webhooks list: https://docs.smooch.io/rest/#operation/createIntegration

Related

Trying to make a POST request, works with cURL, get a 403 when using Python requests

I'm trying to get some JSON data from this API - https://ped.uspto.gov/api/queries
This cURL request works fine and returns what is expected:
curl -X POST "https://ped.uspto.gov/api/queries" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"searchText\":\"*:*\", \"fq\":[ \"totalPtoDays:[1 TO 99999]\", \"appFilingDate:[2005-01-01T00:00:00Z TO 2005-12-31T23:59:59Z]\" ], \"fl\":\"*\", \"mm\":\"100%\", \"df\":\"patentTitle\", \"facet\":\"true\", \"sort\":\"applId asc\", \"start\":\"0\"}"
I have this python script to do the same thing:
from requests.structures import CaseInsensitiveDict
import json
url = "https://ped.uspto.gov/api/queries"
headers = CaseInsensitiveDict()
headers["accept"] = "application/json"
headers["Content-Type"] = "application/json"
data = json.dumps({
"searchText":"*:*",
"fq":[
"totalPtoDays:[1 TO 99999]",
"appFilingDate:[2005-01-01T00:00:00Z TO 2005-12-31T23:59:59Z]"
],
"fl":"*",
"mm":"100%",
"df":"patentTitle",
"facet":"true",
"sort":"applId asc",
"start":"0"
})
resp = requests.post(url, headers=headers, data=data)
print(resp.status_code)
but it returns a 403 error code and the following response header:
"Date":"Mon, 24 Oct 2022 16:13:58 GMT",
"Content-Type":"text/html",
"Content-Length":"919",
"Connection":"keep-alive",
"X-Cache":"Error from cloudfront",
"Via":"1.1 d387fec28536c5aa92926c56363afe9a.cloudfront.net (CloudFront)",
"X-Amz-Cf-Pop":"LHR50-P8",
"X-Amz-Cf-Id":"RMd69prehvXNAl97mo0qyFtuBIiY8r9liIxcQEmbdoBV1zwXLhirXA=="
I'm at quite a loss at what to do, because I really don't understand what my Python is missing to replicate the cURL request.
Thanks very much.
I was interested in this. I got an account with uspto.gov and acquired an access key. Their other API's work well. But the PEDS API? I kept getting the Cloudflare Gateway Timeout 503 error. While I was on their website, I looked into the PEDS API, I could not load any link to a https://ped.uspto.gov page.
I called them and they gave me an email address. I got this reply:
The PEDS API was taken down, because repeated data mining was bringing the entire PEDS System down.
The PEDS Team is working on a solution to fix the PEDS API, so that it can be re-enabled.
I tried it using PHP.
Cloudflare has been causing a lot of problems for curl.
I got a timeout.
I may have gotten past the 403 Forbidden, but did not have credentials and so the server dropped the connection.
An HTTP 504 status code (Gateway Timeout) indicates that when
CloudFront forwarded a request to the origin (because the requested
object wasn't in the edge cache), one of the following happened: The
origin returned an HTTP 504 status code to CloudFront. The origin
didn't respond before the request expired.
AWS Cloudflare Curl Issues
bypassing CloudFlare 403
How to Fix Error 403 Forbidden on Cloudflare
403 Forbidden cloudflare
██████████████████████████████████████████████████████████████
This is a conversion from you curl.
The Content-Type:application/data is added by default when you send JSON data.
I do not know about your json_data.dump or you putting the JSON in parentheses.
import requests
headers = {
'accept': 'application/json',
}
json_data = {
'searchText': '*:*',
'fq': [
'totalPtoDays:[1 TO 99999]',
'appFilingDate:[2005-01-01T00:00:00Z TO 2005-12-31T23:59:59Z]',
],
'fl': '*',
'mm': '100%',
'df': 'patentTitle',
'facet': 'true',
'sort': 'applId asc',
'start': '0',
}
response = requests.post('https://ped.uspto.gov/api/queries', headers=headers, json=json_data)

Executing a PATCH api call from powershell

I'm trying to run the following API 'Patch' command from powershell which I'm looking to execute a release in Azure DevOps ...
$deploy = Invoke-RestMethod -Uri $patchurl -Method Patch -Body $body -Headers $header -ContentType "application/json-patch+json"
The url example is below
https://vsrm.dev.azure.com/test/Fixed%20Income/_apis/Release/releases/567/environments/1072?api-version=6.0-preview.6
The body of the patch call is ...
"Status": "inProgress",
"scheduledDeploymentTime": null,
"comment": null,
"variables": {}
Running the invoke command from powershell returns the following response ...
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred. Activity Id:
759888ab-9828-4cb6-ba2f-e90cde1cd39a.","typeName":"System.Web.Http.HttpResponseException, System.Web.Http","typeKey":"HttpResponseException","errorCode":0,"eventId":0}
When I run the same url to run a 'patch' request from Postman I get the below response, which is what I'm expecting to get from Powershell.
"$id": "1",
"innerException": null,
"message": "TF400813: The user '' is not authorized to access this resource.",
"typeName": "Microsoft.TeamFoundation.Framework.Server.UnauthorizedRequestException, Microsoft.TeamFoundation.Framework.Server",
"typeKey": "UnauthorizedRequestException",
"errorCode": 0,
"eventId": 3000
Any ideas what I'm doing wrong?
According to your description, when you call this REST API from Postman, the response returns an error: "message": "TF400813: The user" is not authorized to access this resource." The cause of this problem is incorrect authorization.
Please create a new personal access token in the organization first, then select the type: Basic Auth in the Authorization tab, and type your PAT in the password input box on the right.
When you call this REST API from powershell, the response returns an error: "TF400898: An Internal Error Occurred. Activity Id: 759888ab-9828-4cb6-ba2f-e90cde1cd39a." The cause of this problem is Content- Type is incorrect.
Please use ContentType "application/json" instead of ContentType "application/json-patch+json" .
Script template:
$token = "PAT"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$url3="https://vsrm.dev.azure.com/{organization}/{project}/_apis/Release/releases/{releaseId}/environments/{environmentId}?api-version=6.0-preview.6"
$body = "{
`"status`": `"inProgress`",
`"scheduledDeploymentTime`": null,
`"comment`": null,
`"variables`": {}
}"
$response3 = Invoke-RestMethod -Uri $url3 -Headers #{Authorization = "Basic $token"} -Method Patch -Body $body -ContentType application/json
Please refer to the following steps to create a PAT:
From your home page, open your user settings, and then select Personal access tokens.
From your home page, open your user settings, and then select Personal access tokens. Name your token, select the organization where you want to use the token, and then choose a lifespan for your token. Select Create.
When you're done, make sure to copy the token. For your security, it won't be shown again. Use this token as your password.

axios POST method seems to be 'transformed' to OPTIONS method on the fly

I use this sample code:
axios({
method: 'post',
headers: { 'content-type': 'application/json' },
url: 'http://somePlace:8040/someWSendpoint',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
});
But that request never reach its destination. Apparently, because the POST method is transformed to OPTIONS method, and rejected by the endpoint url.
This is what the 'Network' window shows in the Chrome inspector:
Request Method: OPTIONS
Status Code: 405 Method Not Allowed
This is what the 'Console' window shows in the Chrome inspector:
Access to XMLHttpRequest at 'http://somePlace:8040/someWSendpoint' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr.js?b50d:160 POST http://somePlace:8040/someWSendpoint net::ERR_FAILED
dispatchXhrRequest # xhr.js?b50d:160
xhrAdapter # xhr.js?b50d:11
dispatchRequest # dispatchRequest.js?5270:59
Promise.then (async)
request # Axios.js?0a06:51
wrap # bind.js?1d2b:9
send_firma # AltaFirma.vue?c240:504
click # AltaFirma.vue?3ed8:1812
invokeWithErrorHandling # vue.runtime.esm.js?2b0e:1854
invoker # vue.runtime.esm.js?2b0e:2179
original._wrapper # vue.runtime.esm.js?2b0e:6917
createError.js?2d83:16 Uncaught (in promise) Error: Network Error
at createError (createError.js?2d83:16)
at XMLHttpRequest.handleError (xhr.js?b50d:69)
I am wondering if people "at the other side" need to configure something related to that CORS thing in his server ¿?
Any help will be very appreciated.

Upload rvt then try to get model data

https://gist.github.com/kenken64/b40ef906076018dc11aef1929b7e04a5
I am getting the following error after submit a job while checking status
200
application/json; charset=utf-8
b'{"type":"manifest","hasThumbnail":"false","status":"failed","progress":"complete","region":"US","urn":"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Zm9yZ2Vfc2FtcGxlMl9jNmVheHJpZmxxeXp2bWlybXQzMDZoc21hd2VodjlpZy9yYWMxLnJ2dA","version":"1.0","derivatives":[{"name":"LMV Bubble","hasThumbnail":"false","status":"failed","progress":"complete","messages":[{"type":"error","message":"Translation failure","code":"TranslationWorker-InternalFailure"}],"outputType":"svf"}]}'
check complete translate data returned status code 200.
Please help !
https://developer.api.autodesk.com/modelderivative/v2/designdata/job
{"input": {"urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Zm9yZ2Vfc2FtcGxlM19jNmVheHJpZmxxeXp2bWlybXQzMDZoc21hd2VodjlpZy9yYWMxLnJ2dA"}, "output": {"formats": [{"type": "svf", "views": ["2d", "3d"]}]}}
{'Content-Type': 'application/json', 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsImtpZCI6Imp3dF9zeW1tZXRyaWNfa2V5In0.eyJjbGllbnRfaWQiOiJDNmVheHJpRmxRWVp2bWlybXQzMDZIc01BV0VodjlJZyIsImV4cCI6MTUwMTUwMjc2NSwic2NvcGUiOlsiZGF0YTpyZWFkIiwiZGF0YTp3cml0ZSIsImRhdGE6Y3JlYXRlIiwiZGF0YTpzZWFyY2giLCJidWNrZXQ6Y3JlYXRlIiwiYnVja2V0OnJlYWQiLCJidWNrZXQ6dXBkYXRlIiwiYnVja2V0OmRlbGV0ZSJdLCJhdWQiOiJodHRwczovL2F1dG9kZXNrLmNvbS9hdWQvand0ZXhwNjAiLCJqdGkiOiJYMVh4R1l6UFZGVlpwZHlsR29MTmZKYjh4T2s1N0dEMDE0c2pNWWZhY1pzc1hDNmgwT0o2VTRIUWVhSEZHWGt4In0.janHAXhsbRtNQYZ9q-Pz7IsGZjF0Em_e_UoOurPr-4Q'}
201
application/json; charset=utf-8
b'{"result":"created","urn":"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Zm9yZ2Vfc2FtcGxlM19jNmVheHJpZmxxeXp2bWlybXQzMDZoc21hd2VodjlpZy9yYWMxLnJ2dA","acceptedJobs":{"output":{"formats":[{"type":"svf","views":["2d","3d"]}]}},"registerKeys":["2d8ddceb-9f0a-48e5-ae6e-53839cc6ded6"]}'
translate data returned status code 201.
It seems that you have some wrong configurations while calling the Model Derivative Job API. Please change following line and try it again:
compressedUrn: true to compressedUrn: false, since your model is a RVT file, it's not compressed.
rootFilename: "A5.iam" to rootFilename: "rac1.rvt".
P.S. Please call this API https://developer.api.autodesk.com/modelderivative/v2/designdata/dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Zm9yZ2Vfc2FtcGxlMl9jNmVheHJpZmxxeXp2bWlybXQzMDZoc21hd2VodjlpZy9yYWMxLnJ2dA/manifest to delete the failure job before you resent the translation job.

HTTP 400 error on Orion NGSI10 convenience operations

I receive an HTTP 400 error using convenience operations on Orion:
Request:
GET /v1/contextEntities/mydevice
HTTP/1.1 Host: XXX.XXX.XXX.XXX:1026
Content-Type: application/json
Accept: application/json
Fiware-Service: myfiwareservice
Fiware-ServicePath: /
X-Auth-Token:XXXXXXXXXXX
Response:
{
"orionError": {
"code": "400",
"reasonPhrase": "Bad Request",
"details": "Sorry, no request treating object found for RequestType /IndividualContextEntity/"
}
}
I've verified that my entity exists using the regular NGSI10 operation, that works fine.
The problem arises when the Context Broker is protected with a PEP proxy and it receives a request that:
Has the header 'Content-type: application/json'
Doesn't have any body
In this case, due to some libraries used, the PEP Proxy forwards the request adding an empty JSON body, that arrives to the Context Broker, causing the error you mentioned.
The solution in this case is to remove the 'Content-type: application/json' header from the requests that do not have any body (typically GET requests).
EDIT: In the above answer we refer to Steelskin PEP implementation. Other PEP implementations could behave differently.