Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch operation not working #168

Open
aqua-regia opened this issue May 16, 2018 · 1 comment
Open

Batch operation not working #168

aqua-regia opened this issue May 16, 2018 · 1 comment

Comments

@aqua-regia
Copy link

aqua-regia commented May 16, 2018

If I see the response of self.client.batch_operations.create() method and check the _links[1].href I get this URL [https://us18.api.mailchimp.com/3.0/batches/5cfa0d22b8] it says API key missing.
This is my operations object

{"operations": [{"method": "POST", "path": "/lists/1a9865b510/members", "body": "{"email_address": "[email protected]", "status": "subscribed"}"}, {"method": "POST", "path": "/lists/1a9865b510/members", "body": "{"email_address": "[email protected]", "status": "subscribed"}"}, {"method": "POST", "path": "/lists/1a9865b510/members", "body": "{"email_address": "[email protected]", "status": "subscribed"}"}]}

And this is my reponse object

{'id': '5cfa0d22b8', 'status': 'pending', 'total_operations': 0, 'finished_operations': 0, 'errored_operations': 0, 'submitted_at': '2018-05-16T06:18:16+00:00', 'completed_at': '', 'response_body_url': '', '_links': [{'rel': 'parent', 'href': 'https://us18.api.mailchimp.com/3.0/batches', 'method': 'GET', 'targetSchema': 'https://us18.api.mailchimp.com/schema/3.0/Definitions/Batches/CollectionResponse.json', 'schema': 'https://us18.api.mailchimp.com/schema/3.0/CollectionLinks/Batches.json'}, {'rel': 'self', 'href': 'https://us18.api.mailchimp.com/3.0/batches/5cfa0d22b8', 'method': 'GET', 'targetSchema': 'https://us18.api.mailchimp.com/schema/3.0/Definitions/Batches/Response.json'}, {'rel': 'delete', 'href': 'https://us18.api.mailchimp.com/3.0/batches/5cfa0d22b8', 'method': 'DELETE'}]}

Whereas all my other operations like get all lists are working fine.

I even used MailChimp API 3.0, but that also showed me the same error.

If I create lists using below it works

json_response = requests.get(endpoint, auth=self._auth, params=params).json()

Whereas the below gives the same error

json_response = requests.post(self._batch_operation_endpoint, data=operations, auth=self._auth, headers={'content-type':'application/json'})

{"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"API Key Missing","status":401,"detail":"Your request did not include an API key.","instance":"a654b813-a530-4acb-8599-69bc9cad4717"}

And this is my batch_operation_endpoint

'https://us18.api.mailchimp.com/3.0/batches'

@anestesya
Copy link

anestesya commented Feb 24, 2019

Hi @aqua-regia i have lost 6 hours to found my error in the body of the batch operations in insert subscribes into lists, i used json.dumps(body)

def _get_data(e, to=None):
  _data = {
    "method": "POST",  # The http verb for the operation
    "path": "/lists/{}/members".format(res['id']),  # The relative path of the operation
    # "operation_id": "my-id",  # A string you provide that identifies the operation
    # "params": {
    #   "id": res['id']
    # },  # Any URL params, only used for GET
    "body": {
      'status': 'subscribed',
      'merge_fields': {},
    }  # The JSON payload for PUT, POST, or PATCH
  }

  _data['body']['email_address'] = e.email
  _data['body']['merge_fields']['FNAME'] = e.nome.encode('utf-8')

  if to == 'lote':
    _data['body'] = json.dumps(_data['body'])

  return _data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants