SAP CPI HTTP Post how to pass token - http

I need to send a POST in CPI to a s4hana service, and in order to pass it directly in JSON, not in xml, I want to use the simple HTTP adapter.
How can I get the token with a GET and use it with a POST afterwards?

do the GET, parse the XML and save the token as a variable in message header.
Use the message header variable in your POST via filling the JSON with ${header.yourVariableName}
see this:
https://blogs.sap.com/2018/01/18/sap-cpi-clearing-the-headers-reset-header/
http://blog.whint.de/runtime-variables-cpi/

Related

Can I have a body and a file in the Form-Data of a http request

I'm working in a Go Lang REST API repo.
I'm wanting to build an endpoint that will take in a file (as part of the form-data, so I suppose I'll use request.FormFile('my-file-key')). This endpoint should also take in a body of a JSON model (which i suppose would be decoded with something like this:
var myData model.MyModel
json.NewDecoder(request.Body).Decode(&myData)
But I'm running into a lot of issues. Is it even possible to send both a body and a file in the form-data with a http request?
If I try to send both I get errors from FormFile saying that it can't find the file of the key name (but if I send the exact same request without a body, this error doesn't happen). I guessing it's having trouble decoding the request.
What you need is a multipart request. One part can be JSON data, and the other part the file data.
If you're using a Go client to prepare the request, you need to use the mime/multipart package to create a Writer, then use CreatePart to create the JSON part, then the file part, and submit the request to the server.
On the decoding side: since the body is JSON you cannot parse it as a form. You have to use a multipart.Reader to read from the body after you parse the headers. Again, from that reader you get a Part, and read the data from that part. You'll get two parts, one for the JSON data and one for the file data.

How to execute a Scrapy request immediately and get the returned response in parse method?

How to execute a Scrapy request immediately and get the returned response in parse method?
I need to get some information from another link and combine it with the current information I have from the original link (in parse method). Therefore, I need to be able to execute a scrapy request and get the returned response.
I think you are looking for ScrapyRT (scrapy real time)
https://blog.scrapinghub.com/2015/01/22/introducing-scrapyrt-an-api-for-scrapy-spiders/
See example http://localhost:9080/crawl.json?spider_name=foo&url=http://example.com/product/1
ScrapyRT will schedule a request in Scrapy for the URL specified and use the ‘foo’ spider’s parse method as a callback. The data extracted from the page will be serialized into JSON and returned in the response body.

How to pass dynamic headers to the Http Request in jMeter?

There is a initial request going to the server which should retrieve the CSRF token and use that token id in post request header.
if that does not happen any POST requests to the server will return that error.
In the above screen shot, where token is the request to get the CSRF token Id, If I run the test this will generate one dynamic random token ID. But I need to pass the generated token ID in the post request through Header Manager. How can it possible. If yes, Can any one suggest some way to do that.
I resolved it by using User defined variables and Regular Expression Extractor to pass the parameters from one request sampler to another.
In the firs request add a postprocesor of the request. if the response is un json format user json Extractor, in json Extractor define a variable that read the token
In the second request add a header Manager an refer varaible declare in json Extractor in the following way in value cell, ${variable}

how do i resend a request after processing it inside my apigee endpoint

I have a endpoint called get user data which accepts a token
I need to read this token in my apigee and send it to tokenVarificationExtUrl
which gets back to me with
a) valid 200
b) userid attached with that token
now what i have to do is i need to read the response header and then conditionally check it for 200 success and then extract the userid from the response.
Once its extracted i need to attach it with another request; which i need to send to getUserData external url
which will get back to me with required user details.
I am successful of extracting data and doing conditional check. I am seeking help for
how do i send another request to getUserData external url.
You need to use a few policies in your proxy.
For example
For checking a header and throwing an error, you may want to use rasie fault policy conditionally
For making an API call to external end-point you can use service callout policy or a standard target
For exrtacting response data from json or xml payload you can use json path of xpath policies
and so on.
I suppose you may want to take a look at a few sample proxies with these functions to be able to design your own.
Check this link out. http://apigee.com/docs/content/using-sample-api-proxies

Amazon Dynamodb Exception error

when we are calling dynamodb with http rest api it is giving this error
Can i know what is the problem? what are all the required things we need to append in the dynamodb url??
http://dynamodb.us-east-1.amazonaws.com/?aws_access_key=XXXXXXXXXXXXXXXX&aws_secret_access_key=ZZZZZZZZZZZZZZZZZZZZZZ
Do we need to append anything more parameters with this url please let me know??
http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/UsingJSON.html#JSONMajorExample
Your solution is in the same link
http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/MakingHTTPRequests.html
If you don't use one of the AWS SDKs, you can perform Amazon DynamoDB operations over HTTP using the POST request method. The POST method requires you to specify the operation in the header of the request and provide the data for the operation in JSON format in the body of the request.
You need to make POST request with all the required parameters mentioned in that page.

Resources