I'm trying to reach SAP Business One Service Layer APU via PostMan and Python (with requests module). However, when I try to POST to /Login endpoint to our Service Layer it gives me the following JSON result:
{ "error": { "code": -304, "message": { "lang": "en-us", "value": "" } } }
As you can see, it's an error code -304 with an empty message value.
The payload I'm sending is a text like this:
{"UserName":"my_username","Password":"my_password","CompanyDB":"NAME_OF_MY_DB"}
I have tried this payload as well to /Login enpoint but with no successful result:
{"Username":"my_username","Password":"my_password","CompanyDB":"NAME_OF_MY_DB"}
but this results in this JSON result:
{ "error": { "code": 102, "message": { "lang": "en-us", "value": "Invalid login credential." } } }
Can anyone, please, suggest what may be wrong here? I need to Login and then GET the Items from the DB.
Thank you in advance
The issue was that I needed to use a domain before the username. So, at the end, the working payload looks like this:
{"UserName":"my_domain\\my_username","Password":"my_password","CompanyDB":"NAME_OF_MY_DB"}
I tried to search conversation from Intercom API using Postman but it always return server error message.
I just followed their API docs.
request url: POST https://api.intercom.io/conversations/search?query=updated_at>1590278400
The query should be in JSON format in the Body, not in the querystring like you do in your example:
{
"query": {
"field": "updated_at",
"operator": ">",
"value": 1590278400
}
}
In Postman it looks like this (note: don't forget to add your authentication)
I am trying to upload an email to gmail account using gmail REST API for import message https://developers.google.com/gmail/api/v1/reference/users/messages/import#http-request using python requests module. email is in RAW format (i.e. data of .eml file encoded with base64.b64encode()) with body
POST https://www.googleapis.com/gmail/v1/users/me/messages/import
{
"raw": ".........."
}
This is working for RAW data size up to few MBs (say 5MB), but I am getting 'Connection Timeout' error if i try to upload bigger data (~10 MB or more).
Can anybody tell me the way to upload bigger email data using this API.
I am using OAuth access_token to call these APIs
Try setting the uploadType to resumable
Resumable upload
To upload data files more reliably, you can use the resumable upload protocol. This protocol allows you to resume an upload operation after a communication failure has interrupted the flow of data. It is especially useful if you are transferring large files and the likelihood of a network interruption or some other transmission failure is high, for example, when uploading from a mobile client app. It can also reduce your bandwidth usage in the event of network failures because you don't have to restart large file uploads from the beginning.
Example: Resumable session initiation request
POST /upload/gmail/v1/users/userId/messages/send?uploadType=resumable HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer your_auth_token
Content-Length: 38
Content-Type: application/json; charset=UTF-8
X-Upload-Content-Type: message/rfc822
X-Upload-Content-Length: 2000000
{
"id": string,
"threadId": string,
"labelIds": [
string
],
"snippet": string,
"historyId": unsigned long,
"payload": {
"partId": string,
"mimeType": string,
"filename": string,
"headers": [
{
"name": string,
"value": string
}
],
"body": users.messages.attachments Resource,
"parts": [
(MessagePart)
]
},
"sizeEstimate": integer,
"raw": bytes
}
I see in the API Gateway FAQ that it is possible to access the request headers sent to the API Gateway...
If you already utilize OAuth tokens or any other authorization
mechanism, you can easily setup API Gateway not to require signed API
calls and simply forward the token headers to your backend for
verification.
However, I can find no example of how to do so in the documentation and it is unclear how to access this data using Lambda.
I am able to set up an open API and gain access to the JSON object that is part of a POST (Walkthrough: API Gateway and Lambda Functions), but in order to implement a OAuth 2.0 style API with my own provider I need access to the "Authorization" header.
My preference is to set this up using Lambda and Java 8, but an example using node.js would also be helpful in understanding how to accomplish this.
You can use the following Mapping Template in the Integration Request to generically map all path, query, and header parameters into the Lambda event. You will still need to register them in the Method Request section of the API Gateway but you can at least decouple the Mapping Template from the specific parameters you want to use. This way you don't have to change the Mapping Template code each time you change headers, query, or path parameters.
I wrote a blog post that gives more detail and some explanation of the Mapping Template: http://kennbrodhagen.net/2015/12/06/how-to-create-a-request-object-for-your-lambda-event-from-api-gateway/
Here is the Mapping Template you can use:
{
"method": "$context.httpMethod",
"body" : $input.json('$'),
"headers": {
#foreach($param in $input.params().header.keySet())
"$param": "$util.escapeJavaScript($input.params().header.get($param))" #if($foreach.hasNext),#end
#end
},
"queryParams": {
#foreach($param in $input.params().querystring.keySet())
"$param": "$util.escapeJavaScript($input.params().querystring.get($param))" #if($foreach.hasNext),#end
#end
},
"pathParams": {
#foreach($param in $input.params().path.keySet())
"$param": "$util.escapeJavaScript($input.params().path.get($param))" #if($foreach.hasNext),#end
#end
}
}
First, you need to trap the Authorization header from the HTTP GET request. Then you need to map that value to the Lambda event object.
Go to the API method dashboard and click on Method Request. In there you can add an HTTP Request Header called Authorization as shown below.
This will trap the Authorization header so you can use it later.
Now go back to the method dashboard and click on Integration Request. From here you can pass the value of the header into the Lambda function by using a mapping like this.
{
"Authorization": "$input.params('Authorization')"
}
Now in your Lambda function you can get the value like this.
event.Authorization
You need to create input mapping inside Integration Request panel on the dashboard screen describing your API method.
Following code translates name query input parameter into Lambda Event input object:
{
"name": "$input.params('name')"
}
Screenshot:
You can find more info about this in the original API Gateway to Lambda input thread on AWS Forums.
while this is an old thread, I have found it best to use lambda proxy integration for the purpose. With this you do not have to configure anything in the API gateway and you get all the headers in your lambda function...
https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
As per Prabhat's answer setting up with the lambda proxy integration request is the simplest way to do this, after which you can access the request headers, path parameters and query parameters via
event['pathParameters']['param1']
event["queryStringParameters"]['queryparam1']
event['requestContext']['identity']['userAgent']
event['requestContext']['identity']['sourceIP']
This is an example event object:
{
"requestContext": {
"elb": {
"targetGroupArn": "arn:aws:elasticloadbalancing:us-east-2:1234567890123:targetgroup/lambda-279xxxxxxx5rsrxxxxxx/49e9d6xxxxxxxxx"
}
},
"httpMethod": "GET",
"path": "/lambda",
"queryStringParameters": {
"query": "1234ABCD"
},
"headers": {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding": "gzip",
"accept-language": "en-US,en;q=0.9",
"connection": "keep-alive",
"host": "lambda-alb-12356789012.us-east-2.elb.amazonaws.com",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
"x-amzn-trace-id": "Root=1-5c5xxxxx-3d683b8xxxxxxxxxx",
"x-forwarded-for": "xx.xx.xxx.xxx",
"x-forwarded-port": "80",
"x-forwarded-proto": "http",
"x-imforwards": "20"
},
"body": "",
"isBase64Encoded": false
}
The event object contains "headers" in it, you can access request headers sent to API gateway by using: event.headers.<header key>
The solution by kennbrodhagen worked great for me, see his answer and blog for the details. Since the poster expressed a preference for Java implementation, and it took me a while to figure out how to implement Kenn's handler in java, I'm just sharing the Java code that corresponds:
public class MyHandler implements RequestHandler<Map<String,Object>,String> {
#Override
public String handleRequest(Map<String,Object> eventMap, Context context) {
LambdaLogger logger = context.getLogger();
logger.log("Body:" + eventMap.get("body"));
logger.log("Headers:" + eventMap.get("headers"));
logger.log("Method:" + eventMap.get("method"));
logger.log("Params:" + eventMap.get("params"));
logger.log("Query:" + eventMap.get("query"));
return("{}");
}
}
For .Net Core 3.1+
If you have enabled Lambda Proxy integration you just have to check the Headers collection in your Lambda handler:
public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest data, ILambdaContext context)
{
if (data.Headers.ContainsKey("x-api-key"))
{
...
}
I have server. He return json in next format:
{
"count": 6,
"next": null,
"previous": null,
"results": [
{
"id": 2,
"court": "http://reg-corruption.herokuapp.com/api/court/2/",
"result": "result2",
"date_meeting": "2014-03-12T17:50:30Z"
},
{
"id": 3,
"court": "http://reg-corruption.herokuapp.com/api/court/2/",
"result": "result22",
"date_meeting": "2014-03-13T17:50:46Z"
}, ] }
I want to write client. In client I can copy models.py, but how I can use it to send request to server. Main problem: I have file models.py and it is work with sqlite database. Can I use this file to connect to REST server? And can I load links to foreign key automatically?
Or what I mast to read or use?
You need neither the models.py nor DB to connect to the server. Once you have the REST API url, required headers and authentication details, you can just write a REST client in any language you are comfortable in and connect to the server.
I will put few examples:
Python : Rest-api-in-python
Python : python-rest-client
Java : java-restful-client
From you tags I understand you are using DRF for the server. You can check http://www.django-rest-framework.org/api-guide/testing/ also, for inbuilt testing REST client library in DRF.