A collection of text elements within an API request,

Correct Answer below.

I need help with selecting products in bulk rather than individual calls. I've tried multiple syntax combinations but keep receiving 404 or 405 errors.

I'm trying to compile a list of product codes, but the error codes persist.

Instructions: /products/bulk

productCodes
required
Array of strings <= 500 items
List of product codes for which to retrieve full product details

Request sample:

{
"productCodes": [
"5010SYDNEY",
"2050_PA",
"2855KENNEDY_TKTS"
]
}

My code:

// Product codes
const List productCodes = [
    '58109P2', '127269P1',
    '127269P1', '250556P1', '204123P16',       
  ];


try {
      var response = await http.post(
          Uri.parse("https://api.viator.com/partner/products/bulk?$productCodes"),
          headers: headers);

      if (response.statusCode == 200) {
        var jsonData = json.decode(response.body);    
        print(jsonData);

      } else {
            print(response.statusCode);

      } catch (e) {

      print(e);

      }

While I can successfully connect and retrieve results for a single product, I am struggling with passing an array of strings in the query parameter.

Thanks

Answer №1

To ensure the page loads smoothly, a few tweaks need to be made. Specifically, the product codes must be placed within a string.

 var productCodes =
        '{"productCodes": ["58109P2","127269P1","250556P1"]}';

Subsequently, they should be included in a post request.

var url = Uri.parse('https://api.viator.com/partner/products/bulk');
var response = await http.post(url, headers: headers, body: productCodes);

The resulting response will contain an instance of the object.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the wonders of jquery's JSON parsing capabilities

Having trouble parsing the JSON data that is out of my control. Can anyone help me figure out what I'm doing wrong here? data.json { "img": "img1.jpg", "img": "img2.jpg", "size": [52, 97] } { "img": "img3.jpg", "img": "img4.jpg", "size ...

Displaying properties of objects in javascript

Just starting with JavaScript and struggling to solve this problem. I attempted using map and filter but couldn't quite implement the if condition correctly. How can I find the records in the given array that have a gender of 0 and color is red? let s ...

Developing a responsive table with AngularJS and integrating it with a restful API

I am encountering an issue while trying to create a table using Quandl's RESTful API in conjunction with AngularJS. Despite successfully creating table headers, the rows remain empty without any data. Below is my controller: angular.module('sto ...

GSON is able to convert JSON data into an array even if the original source is

My aim is to deserialize this data using GSON into a list of Post objects. The challenge I'm facing is how to instruct GSON to ignore the root element "posts" (since it's an object) and focus only on processing the array. This is what I currentl ...

Running Javascript based on the output of PHP code

I have been working on my code with test.php that should trigger some Javascript when my PHP code, conditional.php, detects input and submits it. However, instead of executing the expected "Do Something in Javascript," it outputs "Not empty" instead. I fin ...

Error Mongoose REST API HTTP Status Codes

When an error could occur while attempting to retrieve all banks from the mongoose database with a client action, what status code should I use? Client's Action GET Url: /banks Mongoose Code Banks .find() .exec(function(err, banks) { if (e ...

Decomposing the Retrofit response.body()

I am having difficulties with implementing Retrofit and understanding how to interpret the response body. I believe that there might be an issue with mapping my JSON data to POJO because the output is not what I expected when I print it out in the log. He ...

Error encountered while attempting to make AJAX call: "`$.ajax` parse error on JSON object: {"vErrorsFound":true,"vMessage"

I am trying to update my code from using jQuery 1.3.2 to jQuery 1.5, but I am facing issues with parsing JSON data. I have a PHP script that returns the following JSON object using json_encode: {"vErrorsFound":true,"vMessage":"Login Failed"} I have exper ...

OutOfBoundsException due to an invalid index value for the string length

I've recently started working with Android and I'm trying to send the value of an editText using JSON to a server. However, I keep encountering an error "StringIndexOutOfBoundsException" and I'm unsure of how to resolve it. Here is my code: ...

Jackson's @JsonView is not functioning properly as per expectations

Currently, I am working with Jackson JSON 1.9.12 in conjunction with SpringMVC. As part of this, I have created a data transfer object (dto) with JSON fields. To have two profiles of the same dto with different JSON fields, I took the approach of creating ...

Merge arrays with identical names within the same object into one cohesive object containing all elements

I just started using Vue and I'm not entirely sure if it's possible to achieve what I have in mind. Here is the structure I have: { "items":[ { "total":1287, "currency":"USD", "name":"string", "itemID":"", "pro ...

Error: Found an unconventional token "e" in JSON data at position 1 during parsing in JSON.parse function

Is there a way to retrieve a string value by calling an API in Angular? Here is my approach: Service file - public getRespondDashboardUrl(): Observable<any> { return this.http.get(`ref/RespondDashboardUrl`); } Component File respondDashboar ...

What is the best way to transform a JavaScript object into a JavaScript literal?

Currently, in my nodejs project, I have an object defined as follows: const objA = { key : 'value' }; My goal is to create a new file named obja.js which should contain the same literals from the object, rather than as a JSON literal. How can I ...

Untangling Internet JSON data

I am attempting to parse the JSON string into objects and then display it in a richtextbox public void Form1_Load(object sender, EventArgs e) { using (var webClient = new System.Net.WebClient()) { var json = webClient.Dow ...

There seems to be an issue with ngOptions in Angular as it is

Calling all angularjs experts for assistance... Currently integrating cake with angular. Utilizing a rest controller to enable communication and retrieve options in a serialized json format as displayed below Attempting to populate dropdown options: &l ...

Exploring AngularJS Protractor End-to-End Mocking

In my Angular SPA, I am retrieving data from a node backend that is fully covered with tests. To mock the Angular HTTP calls, I want to implement something like this: Api = $injector.get('Api'); sinon.mock(Api, 'getSomethingFromServer' ...

Using the jq command, you can easily append data to an array at a specific index

I'm currently working on updating specific key values within a particular array element using jq. The JSON structure I have is as follows: [ { "name":"element1", "properties":{ "hardwareProfil ...

What is the best way to handle parsing a JSON in Java that contains a property that could be either a String or an Object?

My backend is using mongodb and nodejs to create an API. The API server will return the same user object in different formats, for example: // curl http://localhost/users/5382f2949a24ed95b44dc04f { id: "5382f2949a24ed95b44dc04f", "name": "jack", "group": ...

Is there a way to simply send the data to the API endpoint without having Django allauth url fetching from react and calling the signup view form?

For my project, I am utilizing React as a standalone Single Page Application (SPA) that connects to a Django backend with allauth for authentication management. When I enter the URL on my local browser (192.168.86.28:8000/accounts/signup/ or 127.0.0.1:8000 ...

Using Python's lambda function to extract data from DynamoDB's JSON structure

I'm looking for a Python Lambda function that can handle DynamoDB streams and convert the JSON data from DynamoDB format to standard JSON. PHP and nodejs have Marshaler options for this task, but I'm interested in finding similar or alternative s ...