Closed josephjclark closed 5 months ago
From the prompt "What can I do?"
Based on the provided OpenFn DSL and the API documentation for the @openfn/language-http@5.0.0 adaptor, you can write job code that interacts with HTTP endpoints. Here's an example job code using the HTTP adaptor to make a GET request:
get('/myEndpoint', {
query: { foo: 'bar', a: 1 },
headers: { 'content-type': 'application/json' },
authentication: { username: 'user', password: 'pass' }
});
This code snippet demonstrates how to use the get
function from the HTTP adaptor to make a GET request to '/myEndpoint' with query parameters, custom headers, and authentication credentials.
Feel free to provide more details about the specific task you want to automate using OpenFn, and I can help you write the corresponding job code.
To remove a member from a mailing list using the @openfn/language-mailchimp@1.0.0 adaptor in OpenFn, you can use the deleteMember
function provided by the adaptor. Here's an example of how you can remove a member from a mailing list:
deleteMember({
listId: "your_list_id_here",
subscriberHash: "subscriber_hash_here"
});
In the above code snippet:
"your_list_id_here"
with the actual ID of the mailing list from which you want to remove the member."subscriber_hash_here"
with the hash of the subscriber you want to remove from the list.Make sure to include this code within a job function in OpenFn to execute the operation.
To defer the post call to only execute the webhook once a second, you can introduce a delay using the fn
operation provided by the OpenFn adaptor. Here's how you can modify your existing code to achieve this:
each(
'$.no_ihs_number[*]',
fn(state => {
return new Promise(resolve => {
setTimeout(() => {
post('https://app.openfn.org/i/2c6ca3cd-d015-4b37-85ea-4c04ce72816b', {
body: state.data,
headers: { 'content-type': 'application/json' },
})(state).then(() => {
resolve(state);
});
}, 1000); // Delay of 1 second (1000 milliseconds)
});
})
);
In this code snippet:
post
operation inside the fn
operation to introduce a delay.setTimeout
to delay the execution of the post
operation by 1 second (1000 milliseconds).fn
operation to ensure that the delay is properly handled.post
operation is executed, and then theThis is spooky.
Here is the input code I gave it:
each(
'$.no_ihs_number[*]',post(
'https://app.openfn.org/i/2c6ca3cd-d015-4b37-85ea-4c04ce72816b', {
body: state.data,
headers: { 'content-type': 'application/json' },
})
})
)
And here is my actual solution:
each(
'$.no_ihs_number[*]',
fn(state => {
return new Promise((resolve) => {
setTimeout(() => {
post(
'https://app.openfn.org/i/2c6ca3cd-d015-4b37-85ea-4c04ce72816b', {
body: state.data,
headers: { 'content-type': 'application/json' },
}, resolve)(state)
}
, 10000)
})
})
)
This PR tweaks the job prompt to try and get better openfn code.
Maybe we should update to GPT 4?
I'm not too concerned about quality yet, but I thought this would be an easy win (it wasn't, and I don't trust it)
Edit: check out what it's generated below - I am fairly happy with them all