Python Forum
How do loop over curl and 'put' different values in API call?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do loop over curl and 'put' different values in API call?
#1
Hi

Objective: How to loop through over curl statement and 'put' key and value into curl put statement

Input: This is my sql query output in json format. for example I mentioned two columns here.

[{'brand_id': 1, 'brand_name': 'Electra'}]
I am using code all below for API call

import http.client

conn = http.client.HTTPSConnection("circleci.com")

payload = "{\"value\":\"xxxxxxxxxxxxxx\"}"

headers = {
    'content-type': "application/json",
    'Circle-Token': "$CIRCLE_TOKEN"
    }

conn.request("PUT", "/api/v2/${contextid}/environment-variable/xxxxxxxxxx", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
Now, brand_id which is first key in my json output should be passed as url dynamically in loop one bye one i.e first iteration its brand_id in url and '1' as value in --data section

in next iteration in url it should pass "brand_name" and values as "Electra"

How to acheive this ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop through values and compare edroche3rd 6 704 Oct-18-2023, 04:04 PM
Last Post: edroche3rd
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,152 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,510 Jul-27-2022, 08:50 PM
Last Post: rob101
  Loop through values in dictrionary and find the same as in previous row Paqqno 5 1,922 Mar-27-2022, 07:58 PM
Last Post: deanhystad
  How to add for loop values in variable paulo79 1 1,462 Mar-09-2022, 07:20 PM
Last Post: deanhystad
  how can I correct the Bad Request error on my curl request tomtom 8 5,091 Oct-03-2021, 06:32 AM
Last Post: tomtom
  Values not updating for restful call boomramada 0 1,663 Mar-13-2021, 01:08 PM
Last Post: boomramada
Exclamation Compare values in a for loop. penahuse 1 2,379 Feb-22-2021, 07:01 AM
Last Post: buran
  returning values in for loop Nickd12 4 12,300 Dec-17-2020, 03:51 AM
Last Post: snippsat
  Works with Curl. Can't get it to work in Python bazcurtis 3 2,576 May-07-2020, 07:47 AM
Last Post: bazcurtis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020