-1

I have a function which require to pass some ids as comma seperated to the url string.

My code:

def shipment(self, orderItemIds):
    url = "https://api.flipkart.net/sellers/orders/shipments"
    payload = {'orderItemsIds':orderItemIds}
    return self.session.get(url, data=payload)

I need to pass id1, id2, id3 so that i get a link as:

https://api.flipkart.net/sellers/orders/shipments?orderItemsIds={id1,id2...}

I tried to pass it as a string. and as a list too. But it didn't worked.

oid = 'id1,id2,id3'                     # or
oid = ['id1',id2'','id3']

How to do it?

I passed an id as oiids = '230501592'. On running response.url, it gives me:

https://api.flipkart.net/sellers/orders/shipments?orderItemsIds

It shows that parameter values are not passing in the url string.

4
  • Are you sure you need to have the multiple items in the literal syntax you posted? So { followed by id1, then a comma, etc.? Commented Aug 10, 2015 at 9:43
  • @MartijnPieters, even the API docs are a bit unclear, but it's just id1,id2,.... Commented Aug 10, 2015 at 9:48
  • Ah, Flipkart again. They really need to work on their API documentation.. Commented Aug 10, 2015 at 9:49
  • Yes @MartijnPieters I have to pass atleast 1 param. multiple values can help me parse a list of ids. Commented Aug 10, 2015 at 9:57

2 Answers 2

2

I believe what you want is this (where orderItemIds is a list of strings):

def shipment(self, orderItemIds):
    url = "https://api.flipkart.net/sellers/orders/shipments"
    params = {'orderItemsIds': ','.join(orderItemIds)}
    return self.session.get(url, params=params)

The differences from the version you have in the question are that orderItemIds is assumed to be a list of strings and is being joined with commas, and the data keyword is replaced with params, which is the right choice for a GET request.

Sign up to request clarification or add additional context in comments.

3 Comments

It gives %2C in url instead of ,
%2C is the escape code for ,; that's automatically done for compatibility reasons, but they're equivalent. See here for further explanation: stackoverflow.com/questions/21049152/…
A bit more explanation would be helpful; you changed data to params (so that URL query parameters are generated instead of a request body) and joined the ids with commas.
-1

You can easily send get parameters in python requests library-

data = {
    'orderItemsIds': ['id1', 'id2', 'id3']
}

response = requests.get(url, data = data)

3 Comments

data is not the right keyword, and passing it a list will result in multiple instances of orderItemsIds in the URL, not one with a comma-separated list of ids.
You want to use params, not data. The former gives you URL parameters, the latter the request body (use that when POSTing instead).
But passing in the elements as a list will not produce the desired URL anyway. The question isn't clear if the OP can accept orderItemsIds=id1&orderItemsIds=id2&orderItemsIds=id3 or that they really must have orderItemsIds={id1,id2,id3}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.