The following is the code:
import requests
url = 'document_url/documents/batch'
payload = "[{...}, {....}]"
headers = {'Content-type': 'application/json'}
response = requests.post(url, headers=headers, data=payload)
print('response code:', response.status_code)
print('response body:', response.json())
The following yields:
response code: 403
response body: {'message': 'Request forbidden by administrative rules', '__type': 'CloudSearchException'}
The security rules are also opened up to all.
What could be the issue?
As per the discussion forums: https://forums.aws.amazon.com/thread.jspa?threadID=148917
The document url should be:
document_url/2013-01-01/documents/batch
response after posting to the above url:
{
"status": "success",
"adds": 1,
"deletes": 0
}
Related
I have an Axios post request in the react.js app.
the data saved in the endpoint as expected, but I'm not getting the response back. Instead, I'm getting caught "Network error."
Is there a problem with the way I'm sending the data?
Is it related to sending the request not from the server but directly from the front app?
Is it possible that the endpoint cannot send me a response because of a blocked port or something?
let bodyFormData = new FormData()
bodyFormData.append("supplier", "blabla")
bodyFormData.append("tranmode", "A")
bodyFormData.append("ccno", "blabla")
bodyFormData.append("expdate", "blabla")
bodyFormData.append("mycvv", "blabla")
bodyFormData.append("sum", "blabla")
bodyFormData.append("currency", "1")
bodyFormData.append("cred_type", "1")
bodyFormData.append("myid", "123456789")
return axios
.post(url, bodyFormData, {
headers: { "Content-Type": "multipart/form-data" },
})
.then((response) => {
//handle success
console.log(response)
})
.catch((error) => {
console.log(error)
})
The error:
Error: Network Error
at e.exports (createError.js:16)
at XMLHttpRequest.y.onerror (xhr.js:117)
Import requests
Import json
Headers = {
‘Content-Type’: ‘application/json’
‘Accept’: ‘application/json’,
‘X-AUTH-TOKEN’: ‘API KEY’,
}
data = ‘{“modelId”: “12345”, “cmdbId”: “11122222”}’
Response = requests.post(‘https://splunk/api/modelinfo/, headers=headers, data=data, verify=False)
Above code works fine for single Data.
Now, I have >10 line data in text file as below and need to run the POST API in loop for each line.
modelId: 12345 cmdbId: 11122222
modelId: 12346 cmdbId: 11122223
modelId: 12347 cmdbId: 11122224
import requests
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-AUTH-TOKEN': 'API KEY'
}
payload = [
{'modelId': 12345, 'cmdbId': 11122222},
{'modelId': 12346, 'cmdbId': 11122223},
{'modelId': 12347, 'cmdbId': 11122224}
]
for data in payload:
response = requests.post("https://splunk/api/modelinfo/", headers=headers, data=data, verify=False)
if response.status_code in [200, 201, 204]:
print("post successful")
I am trying to create envelope from SDK but getting error like this
Reason: The URL provided does not resolve to a resource.
HTTP response headers: HTTPHeaderDict({'Cache-Control': 'no-cache', 'X-DocuSign-TraceToken': '22dad523-9f77-4b83-9481-1e376faf60d8', 'Date': 'Thu, 05 Dec 2019 13:02:26 GMT', 'Content-Length': '0'})
def worker(args):
"""
1. Create the envelope request object
2. Send the envelope
"""
envelope_args = args["envelope_args"]
#print(args)
#print("envelope arrrgggsss")
#print(envelope_args)
# 1. Create the envelope request object
envelope_definition = make_envelope(envelope_args)
#print(envelope_definition)
# 2. call Envelopes::create API method
# Exceptions will be caught by the calling function
api_client = ApiClient()
api_client.host = args["base_path"]
print(api_client.host)
api_client.set_default_header("Authorization", "token" + args["ds_access_token"])
envelopes_api = EnvelopesApi(api_client)
results = envelopes_api.create_envelope(args['account_id'], envelope_definition=envelope_definition)
#print(results)
envelope_id = results.envelope_id
app.logger.info(f"Envelope was created. EnvelopeId {envelope_id}")
return {"envelope_id": envelope_id}
Before that i try to get the token from the following code
def oauth2_token_request(root_url, username, password,
integrator_key):
url = root_url + '/oauth2/token'
data = {
'grant_type': 'password',
'client_id': integrator_key,
'username': username,
'password': password,
'scope': 'api',
}
headers = {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
}
response = requests.post(url, headers=headers, data=data)
print(response)
if response.status_code != 200:
raise exceptions.DocuSignOAuth2Exception(response.json())
return response.json()['access_token']
def oauth2_token_revoke(root_url, token):
url = root_url + '/oauth2/revoke'
data = {
'token': token,
}
headers = {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
}
response = requests.post(url, headers=headers, data=data)
return response
# if response.status_code != 200:
# raise exceptions.DocuSignOAuth2Exception(response.json())
It seems you are hitting wrong API endpoint as
/restapi/v2.1/accounts/9286679/restapi/v2.1/accounts/9286679/envelopes
whereas the correct URI is
/restapi/v2.1/accounts/9286679/envelopes
check your "base_path" value.
This is my code:
import requests
API key correct
api_key = c87cabcf1b479b807a7b3ba8xxxxxxxxxxxxxx
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Token token=api_key'
}
Getting a List of serves from this API
r = requests.get('https://myserver/api/v1.1/server/', headers = headers, verify=False)
print(r.json())
print (r.status_code)
I am getting the error below. I checked my token correct one and not expires.
r.json() : {'error': {'code': 'error', 'description': 'Authentication credentials were not provided.'}}
r.status_code : 401
I missed somewhere in the header.
I guess problem is may be in your third line of header. Try it like this.
'Authorization': 'Token ' + api_key
I am trying to convert a block of cURL to python requests. I get the following error when I do:
{'error': 'invalid_request', 'error_description': 'request is missing a required parameter or malformed.'}
What am I translating incorrectly?
curl
POST /identity/v1/oauth2/token HTTP/1.1
Host: api.sandbox.ebay.com
Authorization: Basic <B64-encoded-oauth-credentials>
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&code=<URL-decoded-auth-code>&redirect_uri=<your_redirect_uri>
my_call.py
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
a 'Authorization': f'Basic {<Base64 encoded value>}'
}
data = {
'grant_type': 'authorization_code',
'code': client_id # str,
'redirect_uri': url # str,
'scope': 'https://api.ebay.com/oauth/api_scope/sell.inventory.readonly',
}
def get_oath_token():
url = 'https://api.ebay.com/identity/v1/oauth2/token'
r = requests.post(url, headers=headers, data=data)
print(r.json())