Skip to main content
Solved

400 status: profiles is a required parameter


Forum|alt.badge.img+2

I’m setting up a Lambda function that will handle adding people to a List/Segment via API like in the example here: https://developers.klaviyo.com/en/reference/add-members.

Here is my snippet of code:

//url is in format of 'https://a.klaviyo.com/api/v2/list/LIST_ID/members?api_key=API_KEY'

exports.handler = async function(event) {
    console.log('Received event:', JSON.stringify(event, null, 2));

    const options = {
        method: 'POST',
        headers: {Accept: 'application/json', 'Content-Type': 'application/json'},
        body: JSON.stringify(event),
    };


    const promise = await new Promise(function(resolve, reject) {
        https.get(url, options, (res) => {
            res.on('data', (d) => {console.log('response:', d.toString())});
            resolve(res.statusCode)
          }).on('error', (e) => {
              console.log('error:', e.toString());
            reject(Error(e))
          })
        });

    console.log("HELLO?");
    console.log(promise);
    return promise

}

//results

2022-03-05T20:08:20.031Z	8f81d290-144e-4c44-a590-ad3b77f05c42	INFO	Received event: {
  "profiles": {
    "email": "george.washington@klaviyo.com"
  }
}
2022-03-05T20:08:20.276Z	8f81d290-144e-4c44-a590-ad3b77f05c42	INFO	response: {"detail":"profiles is a required parameter."}
2022-03-05T20:08:20.276Z	8f81d290-144e-4c44-a590-ad3b77f05c42	INFO	HELLO?
2022-03-05T20:08:20.277Z	8f81d290-144e-4c44-a590-ad3b77f05c42	INFO	400


I am providing input in the following format:
{
  "profiles": {
    "email": "george.washington@klaviyo.com"
  }
}
This call would work in Postman, but not on AWS lambda. Am I missing something else?
 

Best answer by David To

Hello@atini,

Are you sure that the call worked in Postman? 

It sounds like you may be receiving a “profiles is a required parameter” response based on how you have set the ”profiles” as an object rather than an array. I would suggest updating the { } encapsulating "email": "george.washington@klaviyo.com" to [ ] instead. This is also highlighted in the Add Members to a List document you mentioned as well where the profiles must be an array of objects with an example:

{
     "profiles": [
          {
               "email": "george.washington@klaviyo.com"
          }
     ]
}

I hope this helps!

David

View original
Did this topic or the replies in the thread help you find an answer to your question?

3 replies

David To
Klaviyo Employee
Forum|alt.badge.img+60
  • Klaviyo Employee
  • 2456 replies
  • Answer
  • March 9, 2022

Hello@atini,

Are you sure that the call worked in Postman? 

It sounds like you may be receiving a “profiles is a required parameter” response based on how you have set the ”profiles” as an object rather than an array. I would suggest updating the { } encapsulating "email": "george.washington@klaviyo.com" to [ ] instead. This is also highlighted in the Add Members to a List document you mentioned as well where the profiles must be an array of objects with an example:

{
     "profiles": [
          {
               "email": "george.washington@klaviyo.com"
          }
     ]
}

I hope this helps!

David


Forum|alt.badge.img+1
  • Contributor I
  • 1 reply
  • April 1, 2022

@David To I’m running into an issue with this specific API call. The return response is not as expected.

 

I’m adding the user to an existing list that has 80+ members...

 

The API response is “[ ]” however my defined, existing list is set as “Single Opt in” 

 

Any other fields I can pass through to confirm the opt-in?
 

According to the article here, it should not be the case...

https://developers.klaviyo.com/en/reference/subscribe

Note: If you have double opt-in enabled (default behavior), users will not be added to list until they opt-in, and so API will respond with an empty list: []


David To
Klaviyo Employee
Forum|alt.badge.img+60
  • Klaviyo Employee
  • 2456 replies
  • April 6, 2022

Hey @john3783,

That does sound like an odd behavior! Just to make sure, was your list set to single opt-in prior to making this call and was the contact you were attempting to add to the list a net new email/profile? In my experience, if you had previously tested this call with the same contact while double opt-in was still in place, this behavior may occur. 

I think it would be really helpful if you could share your entire call as well to see if other Community members can spot anything that you may have missed. 

David