Agoda rest api issue.. unable to get response from agoda api - api

i am trying to get the hotel lists from the agoda api.. but always end up with this :
The request's Content-Type is not supported. Expected:
application/xml or text/xml or application/json

In postman: Set the headers like this first-
then set the body under raw(json)-
You should get the response like this on send-

Related

Accessing multiple files in a multipart request

Most of the documentation in Mule regarding multipart relates to making a request and not processing an incoming request.
I'm looking to receive multiple files in an incoming request as an array and then loop through them to upload to another service (Salesforce).
Due to the use case I'm sending two properties:
data which is metadata to create a case record
files which is an array of files to be associated with the case record
My Postman request is:
This is the payload I receive in a Mule 4 application (redacted the file data itself):
----------------------------778704367722595657997650
Content-Disposition: form-data; name="data"
Content-Type: application/json
[
{
"subject": "test
}
]
----------------------------778704367722595657997650
Content-Disposition: form-data; name="files"; filename="logo.jpeg"
Content-Type: image/jpeg
jpegdata
----------------------------778704367722595657997650
Content-Disposition: form-data; name="files"; filename="icon.png"
Content-Type: image/png
pngdata
----------------------------778704367722595657997650--
I attempt to get the files with Dataweave:
payload.parts.files
But this returns only the first file 'logo.jpeg'
I've attempted to send the files as files[] but it doesn't seem to send as an array.
It seems that I should loop through the boundary instead? If so, should my request set the boundary so it's the same each time?
Or is there a different way to access the files?
Secondarily, is multipart the correct method or should I utilize application/json instead?
The use case is to send files from a contact form in another application to Salesforce.
When DataWeave parses a multi part input it outputs an object in which each key is the name of the part. Your input has two entries with the same key name. As usual in DataWeave you should use the multi valued selector to get all the values with the same key: payload.parts.*files

Karate: Not able to pass header value extracted from one api response into the request header of another api

Here I'm storing the value of Etag into variable etag, here the values is printed correctly:
Given path '/price/v4/quote/',quoteId,'/products'
And request requestPayload
When method POST
print 'headers:', karate.prevRequest.headers
Then status 200
And def etag = responseHeaders['ETag']
print etag
[print]
["3"]
Now I'm passing it to the request header of another api:
* header If-Match = etag
Given path '/price/v4/quote/',quoteId,'/accept'
And request requestPayload
When method PUT
* print 'headers:', karate.prevRequest.headers
Then status 200
* print karate.pretty(response)
But I'm getting following error as the value of etag header comes with regex:
Got invalid quoteVersion for quote 'b25f50bc-0479-4390-b4fe-0620fc6c6139'. quoteVersion '[\"3\"]', actualVersion '3'"}
I think you missed that responseHeaders is a Map of Lists. Refer the docs: https://github.com/karatelabs/karate#responseheaders
Try this:
And def etag = responseHeaders['ETag'][0]
Also we have a better API for headers in the next versions for anyone else coming across this in the future, please refer: https://github.com/karatelabs/karate/issues/1962

RAML, specify API request Content-Length value

I'm trying to set the value of the Content-Length property to 0 in my RAML file.
I first stumbled upon this thread : How to specify API request header value in RAML
When I tried implementing it with this code :
/update:
post:
description: Store updated data in database
headers:
Content-Length:
enum: [0]
body:
...
I got the response 400 Bad Request :
{
"code": "REQUEST_VALIDATION_ERROR",
"message": "Required header Content-Length is missing."
}
My IDE told me a string was expected but feeding with ["0"] didn't solve the problem.
(I'm testing my API specification in Mulesoft Design Center.)
So is there something I did wrong or is there another way to set the Content-Length to 0 in the request's header ?
You should only try to define custom headers in RAML. A required header of the HTTP protocol like Content-Length must not be defined. It should be automatically generated to prevent errors.

How do I respond to the Dropbox webhook challenge in Dark?

I want to respond to a Dropbox webhook using my Dark app (https://darklang.com/)
It says I need to set some headers to respond to the challenge (https://www.dropbox.com/developers/reference/webhooks)
How do I even set headers in the response?
The trick is twofold:
You need to set the correct headers. This is tricky in Dark, especially with headers that have a dash in the name
And, you need to pull the 'challenge' out of the URL parameters and then put that in the body of the request. Try this:
let body = request.queryParams.challenge
let headers = Dict::empty
|>Dict::set "Content-Type" "text/plain"
|>Dict::set "X-Content-Type-Options" "nosniff"
let response = Http::respondWithHeaders body headers 200
response

Unable to configure Content-Type header from karate

am trying to configure the header 'Content-Type' from karate and I am not able to do so. I tried these * configure headers = {'Content-Type' : 'application/json;charset=UTF-8'} and * header Content-Type = 'application/json;charset=UTF-8'. But in the post call I am making , I always get Content-Type: text/plain which is wrong. Can anyone help? Thanks a lot!
Actually, never mind. I got over this by just adding * header Content-Type = 'application/json' rather than Content-Type' : 'application/json**;charset=UTF-8. I removed ;charset=UTF-8. If i add this, it breaks. I get an error java.lang.IllegalArgumentException: MIME type may not contain reserved characters
at org.apache.http.util.Args.check(Args.java:36).