Skip to main content

I am setting up a new integration and I am successfully getting response data from the authentication. However, when attempting to make a test request to a valid endpoint I am receiving the error

TEST ValueError dictionary update sequence element #0 has length 5; 2 is required

What is this referring to?

Here is the authentication code:

const options = {
url: 'https://myfakeurl.com:8885/abc/api/authentication/GenerateAccessToken',
method: 'POST',
headers: {
'Content-type': 'application/json',
'Accept': 'application/problem+json'
},
params: {

},
body: {
'UserName': bundle.authData.UserName,
'Password': bundle.authData.Password,
'Domain': bundle.authData.Domain,
'AppName': bundle.authData.AppName,
'AppVersion': bundle.authData.AppVersion,
}
}

return z.request(options)
.then((response) => {
response.throwForStatus();
const result = response;

return [result];
});

Here is the code for using the response from the above (to test the authentication):

const options = {
url: `https://myfakeurl.com:8885/ABC/API/v1/{{bundle.authData.Domain/OData/Branches`,
method: 'GET',
headers: {
'Authorization': `Bearer ${result.Api.AccessToken}`,
'Content-type': 'application/json',
'Accept': 'application/json'
},
params: {
}
}

return z.request(options)
.then((response) => {
response.throwForStatus();
const results = response.json;

// You can do any parsing you need for results here before returning them

return results;
});

TIA

So, I think I have fixed the issue (with some outside help).

My new code looks like:

const options = {
url: 'https://myfakeurl.com:8885/abc/api/authentication/GenerateAccessToken',
method: 'POST',
headers: {
'Content-type': 'application/json',
'Accept': 'application/problem+json'
},
params: {

},
body: {
'UserName': bundle.authData.UserName,
'Password': bundle.authData.Password,
'Domain': bundle.authData.Domain,
'AppName': bundle.authData.AppName,
'AppVersion': bundle.authData.AppVersion,
}
}

return z.request(options)
.then((response) => {
response.throwForStatus();
const result = response;

return {
'Code': result.json.Code,
'Message': result.json.Message,
'BaseUrl': result.json.Api.BaseUrl,
'AccessToken': result.json.Api.AccessToken,
'AccessTokenExpiration': result.json.Api.AccessTokenExpiration
};
});

And then my test call:

const options = {
url: `https://mysmp.salesmanagementplus.com:8885/SMP/API/v1/{{bundle.authData.Domain}}/OData/Branches`,
method: 'GET',
headers: {
'Authorization': `Bearer ${bundle.authData.AccessToken}`,
'Content-type': 'application/json',
'Accept': 'application/json'
},
params: {
}
}

return z.request(options)
.then((response) => {
response.throwForStatus();
const results = response.json;

// You can do any parsing you need for results here before returning them

return results;
});

Ultimately, it seems that the data was being passed in an element (i guess the element #0 mentioned in the error?) called ‘json’. After a few missteps here and there I was able to get the references correct. 

 


Hi @Inspiritek - The error is coming from the API itself and not from Zapier so you’ll need to make sure you’re sending the payload in the correct format that the API expects. You might also want to try it out in Postman first.